seawolf2357 commited on
Commit
2d02037
·
verified ·
1 Parent(s): 0a8529b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py CHANGED
@@ -217,7 +217,31 @@ with gr.Blocks(css_paths="app.css") as demo:
217
  sandbox = gr.HTML(elem_classes="html_content")
218
 
219
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
220
 
 
 
 
 
 
 
221
 
222
  settingPromptBtn.click(lambda: gr.update(
223
  open=True), inputs=[], outputs=[system_prompt_modal])
@@ -243,5 +267,6 @@ with gr.Blocks(css_paths="app.css") as demo:
243
 
244
  clear_btn.click(clear_history, inputs=[], outputs=[history])
245
 
 
246
  if __name__ == "__main__":
247
  demo.queue(default_concurrency_limit=20).launch(ssr_mode=False)
 
217
  sandbox = gr.HTML(elem_classes="html_content")
218
 
219
 
220
+ # Code 실행 버튼 이벤트 핸들러
221
+ def execute_code(query: str):
222
+ if not query or query.strip() == '':
223
+ return None, gr.update(active_key="empty")
224
+
225
+ try:
226
+ # HTML 코드 블록 확인
227
+ if '```html' in query and '```' in query:
228
+ # HTML 코드 블록 추출
229
+ code = remove_code_block(query)
230
+ else:
231
+ # 입력된 텍스트를 그대로 코드로 사용
232
+ code = query.strip()
233
+
234
+ return send_to_sandbox(code), gr.update(active_key="render")
235
+ except Exception as e:
236
+ print(f"Error executing code: {str(e)}")
237
+ return None, gr.update(active_key="empty")
238
 
239
+ # execute_btn 이벤트 핸들러 추가
240
+ execute_btn.click(
241
+ fn=execute_code,
242
+ inputs=[input],
243
+ outputs=[sandbox, state_tab]
244
+ )
245
 
246
  settingPromptBtn.click(lambda: gr.update(
247
  open=True), inputs=[], outputs=[system_prompt_modal])
 
267
 
268
  clear_btn.click(clear_history, inputs=[], outputs=[history])
269
 
270
+
271
  if __name__ == "__main__":
272
  demo.queue(default_concurrency_limit=20).launch(ssr_mode=False)