seawolf2357 commited on
Commit
9319937
ยท
verified ยท
1 Parent(s): e4377de

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -2
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
- # ๋ฒ„ํŠผ๋“ค์„ ๊ฐ€๋กœ๋กœ ๋ฐฐ์น˜ํ•˜๊ธฐ ์œ„ํ•œ Flex ์ปจํ…Œ์ด๋„ˆ (ํ•œ ๋ฒˆ๋งŒ ์ถœ๋ ฅ)
 
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__":