Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,6 +17,10 @@ import modelscope_studio.components.antd as antd
|
|
| 17 |
|
| 18 |
import html
|
| 19 |
import urllib.parse
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
# SystemPrompt ๋ถ๋ถ์ ์ง์ ์ ์
|
| 22 |
SystemPrompt = """๋์ ์ด๋ฆ์ 'MOUSE'์ด๋ค. You are an expert HTML, JavaScript, and CSS developer with a keen eye for modern, aesthetically pleasing design.
|
|
@@ -708,6 +712,52 @@ def load_session_history(template_type="best"):
|
|
| 708 |
return gr.HTML("Error loading templates")
|
| 709 |
|
| 710 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 711 |
# Demo ์ธ์คํด์ค ์์ฑ
|
| 712 |
demo_instance = Demo()
|
| 713 |
|
|
@@ -765,13 +815,17 @@ with gr.Blocks(css_paths="app.css",theme=theme) as demo:
|
|
| 765 |
placeholder=random.choice(DEMO_LIST)['description']
|
| 766 |
)
|
| 767 |
|
| 768 |
-
|
|
|
|
| 769 |
with antd.Flex(gap="small", justify="space-between"):
|
| 770 |
btn = antd.Button("Send", type="primary", size="large")
|
| 771 |
execute_btn = antd.Button("Code ์คํ", type="default", size="large")
|
|
|
|
| 772 |
clear_btn = antd.Button("Clear", type="default", size="large")
|
| 773 |
|
| 774 |
-
|
|
|
|
|
|
|
| 775 |
|
| 776 |
with antd.Col(span=24, md=16):
|
| 777 |
with ms.Div(elem_classes="right_panel"):
|
|
@@ -885,6 +939,12 @@ with gr.Blocks(css_paths="app.css",theme=theme) as demo:
|
|
| 885 |
outputs=[history]
|
| 886 |
)
|
| 887 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 888 |
|
| 889 |
|
| 890 |
if __name__ == "__main__":
|
|
|
|
| 17 |
|
| 18 |
import html
|
| 19 |
import urllib.parse
|
| 20 |
+
from huggingface_hub import HfApi, create_repo
|
| 21 |
+
import string
|
| 22 |
+
import random
|
| 23 |
+
|
| 24 |
|
| 25 |
# SystemPrompt ๋ถ๋ถ์ ์ง์ ์ ์
|
| 26 |
SystemPrompt = """๋์ ์ด๋ฆ์ 'MOUSE'์ด๋ค. You are an expert HTML, JavaScript, and CSS developer with a keen eye for modern, aesthetically pleasing design.
|
|
|
|
| 712 |
return gr.HTML("Error loading templates")
|
| 713 |
|
| 714 |
|
| 715 |
+
|
| 716 |
+
|
| 717 |
+
|
| 718 |
+
# ๋ฐฐํฌ ๊ด๋ จ ํจ์ ์ถ๊ฐ
|
| 719 |
+
def generate_space_name():
|
| 720 |
+
"""6์๋ฆฌ ๋๋ค ์๋ฌธ ์ด๋ฆ ์์ฑ"""
|
| 721 |
+
letters = string.ascii_lowercase
|
| 722 |
+
return ''.join(random.choice(letters) for i in range(6))
|
| 723 |
+
|
| 724 |
+
def deploy_to_huggingface(code: str):
|
| 725 |
+
"""HuggingFace Spaces์ ์ฝ๋ ๋ฐฐํฌ"""
|
| 726 |
+
try:
|
| 727 |
+
token = os.getenv("HF_TOKEN")
|
| 728 |
+
if not token:
|
| 729 |
+
return "HuggingFace ํ ํฐ์ด ์ค์ ๋์ง ์์์ต๋๋ค."
|
| 730 |
+
|
| 731 |
+
api = HfApi(token=token)
|
| 732 |
+
space_name = generate_space_name()
|
| 733 |
+
|
| 734 |
+
# Space ์์ฑ
|
| 735 |
+
repo_id = f"{api.whoami()['name']}/{space_name}"
|
| 736 |
+
create_repo(
|
| 737 |
+
repo_id,
|
| 738 |
+
repo_type="space",
|
| 739 |
+
space_sdk="static",
|
| 740 |
+
token=token
|
| 741 |
+
)
|
| 742 |
+
|
| 743 |
+
# index.html ์์ฑ ๋ฐ ์
๋ก๋
|
| 744 |
+
with open("index.html", "w", encoding="utf-8") as f:
|
| 745 |
+
f.write(code)
|
| 746 |
+
|
| 747 |
+
api.upload_file(
|
| 748 |
+
path_or_fileobj="index.html",
|
| 749 |
+
path_in_repo="index.html",
|
| 750 |
+
repo_id=repo_id,
|
| 751 |
+
repo_type="space"
|
| 752 |
+
)
|
| 753 |
+
|
| 754 |
+
# ๋ฐฐํฌ๋ URL ๋ฐํ
|
| 755 |
+
space_url = f"https://huggingface.co/spaces/{repo_id}"
|
| 756 |
+
return f"๋ฐฐํฌ ์๋ฃ! ๋ค์ URL์์ ํ์ธํ์ธ์: {space_url}"
|
| 757 |
+
|
| 758 |
+
except Exception as e:
|
| 759 |
+
return f"๋ฐฐํฌ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
| 760 |
+
|
| 761 |
# Demo ์ธ์คํด์ค ์์ฑ
|
| 762 |
demo_instance = Demo()
|
| 763 |
|
|
|
|
| 815 |
placeholder=random.choice(DEMO_LIST)['description']
|
| 816 |
)
|
| 817 |
|
| 818 |
+
|
| 819 |
+
# UI ์์ ๋ถ๋ถ - antd.Col(span=24, md=8) ๋ด๋ถ์ ๋ฒํผ ์ปจํ
์ด๋์ ๋ฐฐํฌ ๋ฒํผ ์ถ๊ฐ:
|
| 820 |
with antd.Flex(gap="small", justify="space-between"):
|
| 821 |
btn = antd.Button("Send", type="primary", size="large")
|
| 822 |
execute_btn = antd.Button("Code ์คํ", type="default", size="large")
|
| 823 |
+
deploy_btn = antd.Button("๋ฐฐํฌํ๊ธฐ", type="default", size="large") # ์ถ๊ฐ
|
| 824 |
clear_btn = antd.Button("Clear", type="default", size="large")
|
| 825 |
|
| 826 |
+
# ๋ฐฐํฌ ๊ฒฐ๊ณผ๋ฅผ ํ์ํ ํ
์คํธ ์์ญ ์ถ๊ฐ
|
| 827 |
+
deploy_result = gr.Textbox(label="๋ฐฐํฌ ๊ฒฐ๊ณผ", interactive=False)
|
| 828 |
+
|
| 829 |
|
| 830 |
with antd.Col(span=24, md=16):
|
| 831 |
with ms.Div(elem_classes="right_panel"):
|
|
|
|
| 939 |
outputs=[history]
|
| 940 |
)
|
| 941 |
|
| 942 |
+
# ์ด๋ฒคํธ ํธ๋ค๋ฌ ์ถ๊ฐ
|
| 943 |
+
deploy_btn.click(
|
| 944 |
+
fn=lambda code: deploy_to_huggingface(remove_code_block(code)) if code else "์ฝ๋๊ฐ ์์ต๋๋ค.",
|
| 945 |
+
inputs=[code_output],
|
| 946 |
+
outputs=[deploy_result]
|
| 947 |
+
)
|
| 948 |
|
| 949 |
|
| 950 |
if __name__ == "__main__":
|