seawolf2357 commited on
Commit
b32380d
ยท
verified ยท
1 Parent(s): f2615df

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -5
app.py CHANGED
@@ -15,6 +15,7 @@ import modelscope_studio.components.base as ms
15
  import modelscope_studio.components.legacy as legacy
16
  import modelscope_studio.components.antd as antd
17
 
 
18
 
19
  # SystemPrompt ๋ถ€๋ถ„์„ ์ง์ ‘ ์ •์˜
20
  SystemPrompt = """๋„ˆ์˜ ์ด๋ฆ„์€ 'MOUSE'์ด๋‹ค. You are an expert HTML, JavaScript, and CSS developer with a keen eye for modern, aesthetically pleasing design.
@@ -580,6 +581,27 @@ with gr.Blocks(css_paths="app.css",theme=theme) as demo:
580
  elem_classes="close-btn"
581
  )
582
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
583
  # ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ ์ˆ˜์ •
584
  session_list.change(
585
  load_session_history,
@@ -587,10 +609,14 @@ with gr.Blocks(css_paths="app.css",theme=theme) as demo:
587
  outputs=[session_history]
588
  )
589
 
 
 
 
 
 
 
590
 
591
 
592
-
593
-
594
  # ๋ฉ”์ธ ์ปจํ…์ธ ๋ฅผ ์œ„ํ•œ Row
595
  with antd.Row(gutter=[32, 12]) as layout:
596
  # ์ขŒ์ธก ํŒจ๋„
@@ -793,16 +819,20 @@ with gr.Blocks(css_paths="app.css",theme=theme) as demo:
793
  outputs=[session_drawer, session_list]
794
  )
795
 
 
796
  session_drawer.close(
797
- lambda: (gr.update(open=False), gr.update(choices=[]), []),
798
  outputs=[session_drawer, session_list, session_history]
799
  )
800
 
801
  close_btn.click(
802
- lambda: (gr.update(open=False), gr.update(choices=[]), []),
803
  outputs=[session_drawer, session_list, session_history]
804
  )
805
 
 
 
 
806
  session_list.change(
807
  load_session_history,
808
  inputs=[session_list],
@@ -829,4 +859,8 @@ if __name__ == "__main__":
829
  demo.queue(default_concurrency_limit=20).launch(ssr_mode=False)
830
  except Exception as e:
831
  print(f"Initialization error: {e}")
832
- raise
 
 
 
 
 
15
  import modelscope_studio.components.legacy as legacy
16
  import modelscope_studio.components.antd as antd
17
 
18
+ import html
19
 
20
  # SystemPrompt ๋ถ€๋ถ„์„ ์ง์ ‘ ์ •์˜
21
  SystemPrompt = """๋„ˆ์˜ ์ด๋ฆ„์€ 'MOUSE'์ด๋‹ค. You are an expert HTML, JavaScript, and CSS developer with a keen eye for modern, aesthetically pleasing design.
 
581
  elem_classes="close-btn"
582
  )
583
 
584
+ # ์„ธ์…˜ ๋“œ๋กœ์–ด์—์„œ ์นด๋“œ ํด๋ฆญ ์‹œ ์‹คํ–‰ํ•  ํ•จ์ˆ˜ (Drawer ์ปดํฌ๋„ŒํŠธ๋“ค ๋‹ค์Œ์— ์œ„์น˜)
585
+ def execute_history_item(evt: gr.SelectData): # gr.SelectData๋กœ ์ด๋ฒคํŠธ ๋ฐ์ดํ„ฐ ๋ฐ›๊ธฐ
586
+ try:
587
+ # ํด๋ฆญ๋œ ์นด๋“œ์˜ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ
588
+ prompt = evt.value["prompt"]
589
+ response = evt.value["response"]
590
+
591
+ # ์ฝ”๋“œ ์‹คํ–‰
592
+ code = remove_code_block(response) if '```html' in response else response
593
+
594
+ return (
595
+ gr.update(value=prompt), # ์ž…๋ ฅ ํ•„๋“œ ์—…๋ฐ์ดํŠธ
596
+ send_to_sandbox(code), # ์ฝ”๋“œ ์‹คํ–‰
597
+ gr.update(active_key="render"), # ํƒญ ์ƒํƒœ ์—…๋ฐ์ดํŠธ
598
+ gr.update(open=False) # ์„ธ์…˜ ๋“œ๋กœ์–ด ๋‹ซ๊ธฐ
599
+ )
600
+ except Exception as e:
601
+ print(f"Error executing history item: {e}")
602
+ return None, None, gr.update(active_key="empty"), gr.update(open=True)
603
+
604
+
605
  # ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ ์ˆ˜์ •
606
  session_list.change(
607
  load_session_history,
 
609
  outputs=[session_history]
610
  )
611
 
612
+ # ์„ธ์…˜ ํžˆ์Šคํ† ๋ฆฌ ์นด๋“œ ํด๋ฆญ ์ด๋ฒคํŠธ (session_list.change ๋‹ค์Œ์— ์œ„์น˜)
613
+ session_history.click(
614
+ fn=execute_history_item,
615
+ inputs=[],
616
+ outputs=[input, sandbox, state_tab, session_drawer]
617
+ )
618
 
619
 
 
 
620
  # ๋ฉ”์ธ ์ปจํ…์ธ ๋ฅผ ์œ„ํ•œ Row
621
  with antd.Row(gutter=[32, 12]) as layout:
622
  # ์ขŒ์ธก ํŒจ๋„
 
819
  outputs=[session_drawer, session_list]
820
  )
821
 
822
+ # ์„ธ์…˜ ๋“œ๋กœ์–ด ๋‹ซ๊ธฐ ์ด๋ฒคํŠธ ์ˆ˜์ •
823
  session_drawer.close(
824
+ lambda: (gr.update(open=False), gr.update(choices=[]), gr.HTML("")),
825
  outputs=[session_drawer, session_list, session_history]
826
  )
827
 
828
  close_btn.click(
829
+ lambda: (gr.update(open=False), gr.update(choices=[]), gr.HTML("")),
830
  outputs=[session_drawer, session_list, session_history]
831
  )
832
 
833
+
834
+
835
+
836
  session_list.change(
837
  load_session_history,
838
  inputs=[session_list],
 
859
  demo.queue(default_concurrency_limit=20).launch(ssr_mode=False)
860
  except Exception as e:
861
  print(f"Initialization error: {e}")
862
+ raise
863
+
864
+
865
+
866
+