Spaces:
Paused
Paused
Update app.py
Browse files
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 |
+
|