seawolf2357 commited on
Commit
2b21f25
ยท
verified ยท
1 Parent(s): c06d13b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -6
app.py CHANGED
@@ -756,21 +756,18 @@ with gr.Blocks(css_paths="app.css",theme=theme) as demo:
756
  placeholder=random.choice(DEMO_LIST)['description']
757
  )
758
 
759
- # ๋ฒ„ํŠผ๋“ค์„ ๊ฐ€๋กœ๋กœ ๋ฐฐ์น˜ํ•˜๊ธฐ ์œ„ํ•œ Flex ์ปจํ…Œ์ด๋„ˆ๋“ค
760
- with antd.Flex(vertical=True, gap="middle"): # vertical์„ ์‚ฌ์šฉํ•˜์—ฌ ์„ธ๋กœ ๋ฐฉํ–ฅ์œผ๋กœ ๋ฐฐ์น˜
761
  with antd.Flex(gap="small", justify="space-between"):
762
  btn = antd.Button("Send", type="primary", size="large")
763
  execute_btn = antd.Button("Code ์‹คํ–‰", type="default", size="large")
764
  clear_btn = antd.Button("Clear", type="default", size="large")
765
 
766
- # ํ…œํ”Œ๋ฆฟ ๋ฒ„ํŠผ๋“ค์„ ์œ„ํ•œ ์ƒˆ๋กœ์šด Flex ์ปจํ…Œ์ด๋„ˆ
767
  with antd.Flex(gap="small", justify="space-between"):
768
  best_btn = antd.Button("๐Ÿ† ๋ฒ ์ŠคํŠธ ํ…œํ”Œ๋ฆฟ", type="default", size="large")
769
  trending_btn = antd.Button("๐Ÿ”ฅ ํŠธ๋ Œ๋”ฉ ํ…œํ”Œ๋ฆฟ", type="default", size="large")
770
  new_btn = antd.Button("โœจ NEW ํ…œํ”Œ๋ฆฟ", type="default", size="large")
771
-
772
-
773
-
774
 
775
  # ์šฐ์ธก ํŒจ๋„
776
  with antd.Col(span=24, md=16):
@@ -789,6 +786,25 @@ with gr.Blocks(css_paths="app.css",theme=theme) as demo:
789
  with antd.Tabs.Item(key="render"):
790
  sandbox = gr.HTML(elem_classes="html_content")
791
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
792
  # ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ๋“ค
793
  execute_btn.click(
794
  fn=execute_code,
 
756
  placeholder=random.choice(DEMO_LIST)['description']
757
  )
758
 
759
+ # ๋ฒ„ํŠผ๋“ค์„ ๊ฐ€๋กœ๋กœ ๋ฐฐ์น˜ํ•˜๊ธฐ ์œ„ํ•œ Flex ์ปจํ…Œ์ด๋„ˆ
760
+ with antd.Flex(vertical=True, gap="middle"):
761
  with antd.Flex(gap="small", justify="space-between"):
762
  btn = antd.Button("Send", type="primary", size="large")
763
  execute_btn = antd.Button("Code ์‹คํ–‰", type="default", size="large")
764
  clear_btn = antd.Button("Clear", type="default", size="large")
765
 
766
+ # ํ…œํ”Œ๋ฆฟ ๋ฒ„ํŠผ๋“ค์„ ์œ„ํ•œ ์ƒˆ๋กœ์šด Flex ์ปจํ…Œ์ด๋„ˆ
767
  with antd.Flex(gap="small", justify="space-between"):
768
  best_btn = antd.Button("๐Ÿ† ๋ฒ ์ŠคํŠธ ํ…œํ”Œ๋ฆฟ", type="default", size="large")
769
  trending_btn = antd.Button("๐Ÿ”ฅ ํŠธ๋ Œ๋”ฉ ํ…œํ”Œ๋ฆฟ", type="default", size="large")
770
  new_btn = antd.Button("โœจ NEW ํ…œํ”Œ๋ฆฟ", type="default", size="large")
 
 
 
771
 
772
  # ์šฐ์ธก ํŒจ๋„
773
  with antd.Col(span=24, md=16):
 
786
  with antd.Tabs.Item(key="render"):
787
  sandbox = gr.HTML(elem_classes="html_content")
788
 
789
+ # Code ์‹คํ–‰ ๋ฒ„ํŠผ ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ ํ•จ์ˆ˜ ์ •์˜
790
+ def execute_code(query: str):
791
+ if not query or query.strip() == '':
792
+ return None, gr.update(active_key="empty")
793
+
794
+ try:
795
+ # HTML ์ฝ”๋“œ ๋ธ”๋ก ํ™•์ธ
796
+ if '```html' in query and '```' in query:
797
+ # HTML ์ฝ”๋“œ ๋ธ”๋ก ์ถ”์ถœ
798
+ code = remove_code_block(query)
799
+ else:
800
+ # ์ž…๋ ฅ๋œ ํ…์ŠคํŠธ๋ฅผ ๊ทธ๋Œ€๋กœ ์ฝ”๋“œ๋กœ ์‚ฌ์šฉ
801
+ code = query.strip()
802
+
803
+ return send_to_sandbox(code), gr.update(active_key="render")
804
+ except Exception as e:
805
+ print(f"Error executing code: {str(e)}")
806
+ return None, gr.update(active_key="empty")
807
+
808
  # ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ๋“ค
809
  execute_btn.click(
810
  fn=execute_code,