seawolf2357 commited on
Commit
7d4ee49
·
verified ·
1 Parent(s): 7c2ac54

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -0
app.py CHANGED
@@ -605,6 +605,25 @@ with gr.Blocks(css_paths="app.css",theme=theme) as demo:
605
  with antd.Tabs.Item(key="render"):
606
  sandbox = gr.HTML(elem_classes="html_content")
607
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
608
  # 이벤트 핸들러들
609
  execute_btn.click(
610
  fn=execute_code,
 
605
  with antd.Tabs.Item(key="render"):
606
  sandbox = gr.HTML(elem_classes="html_content")
607
 
608
+ # Code 실행 버튼 이벤트 핸들러 함수 정의
609
+ def execute_code(query: str):
610
+ if not query or query.strip() == '':
611
+ return None, gr.update(active_key="empty")
612
+
613
+ try:
614
+ # HTML 코드 블록 확인
615
+ if '```html' in query and '```' in query:
616
+ # HTML 코드 블록 추출
617
+ code = remove_code_block(query)
618
+ else:
619
+ # 입력된 텍스트를 그대로 코드로 사용
620
+ code = query.strip()
621
+
622
+ return send_to_sandbox(code), gr.update(active_key="render")
623
+ except Exception as e:
624
+ print(f"Error executing code: {str(e)}")
625
+ return None, gr.update(active_key="empty")
626
+
627
  # 이벤트 핸들러들
628
  execute_btn.click(
629
  fn=execute_code,