Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -755,17 +755,16 @@ def generate_space_name():
|
|
| 755 |
letters = string.ascii_lowercase
|
| 756 |
return ''.join(random.choice(letters) for i in range(6))
|
| 757 |
|
| 758 |
-
|
| 759 |
def deploy_to_vercel(code: str):
|
| 760 |
-
"""Vercel์ ์ฝ๋ ๋ฐฐํฌ"""
|
| 761 |
try:
|
| 762 |
token = "A8IFZmgW2cqA4yUNlLPnci0N"
|
| 763 |
if not token:
|
| 764 |
return "Vercel ํ ํฐ์ด ์ค์ ๋์ง ์์์ต๋๋ค."
|
| 765 |
|
| 766 |
-
# ํ๋ก์ ํธ ์ด๋ฆ ์์ฑ
|
| 767 |
project_name = ''.join(random.choice(string.ascii_lowercase) for i in range(6))
|
| 768 |
|
|
|
|
| 769 |
# Vercel API ์๋ํฌ์ธํธ
|
| 770 |
deploy_url = "https://api.vercel.com/v13/deployments"
|
| 771 |
|
|
@@ -818,23 +817,87 @@ def deploy_to_vercel(code: str):
|
|
| 818 |
"projectSettings": project_settings
|
| 819 |
}
|
| 820 |
|
|
|
|
| 821 |
deploy_response = requests.post(deploy_url, headers=headers, json=deploy_data)
|
| 822 |
|
| 823 |
if deploy_response.status_code != 200:
|
| 824 |
return f"๋ฐฐํฌ ์คํจ: {deploy_response.text}"
|
| 825 |
|
| 826 |
-
#
|
| 827 |
-
|
| 828 |
-
deployment_url = response_data.get('url', f"{project_name}.vercel.app")
|
| 829 |
|
| 830 |
-
|
| 831 |
-
time.sleep(5) # ๋ฐฐํฌ๊ฐ ์๋ฃ๋ ๋๊น์ง ์ ์ ๋๊ธฐ
|
| 832 |
|
| 833 |
-
return f"""๋ฐฐํฌ ์๋ฃ! <a href="https://{deployment_url}" target="_blank" style="color: #1890ff; text-decoration: underline; cursor: pointer;"
|
| 834 |
|
| 835 |
except Exception as e:
|
| 836 |
return f"๋ฐฐํฌ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
| 837 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 838 |
|
| 839 |
# Demo ์ธ์คํด์ค ์์ฑ
|
| 840 |
demo_instance = Demo()
|
|
@@ -899,15 +962,17 @@ with gr.Blocks(css_paths="app.css",theme=theme) as demo:
|
|
| 899 |
allow_clear=True,
|
| 900 |
placeholder=random.choice(DEMO_LIST)['description']
|
| 901 |
)
|
| 902 |
-
|
| 903 |
-
|
| 904 |
-
# UI ์์ ๋ถ๋ถ - antd.Col(span=24, md=8) ๋ด๋ถ์ ๋ฒํผ ์ปจํ
์ด๋์ ๋ฐฐํฌ ๋ฒํผ ์ถ๊ฐ:
|
| 905 |
with antd.Flex(gap="small", justify="space-between"):
|
| 906 |
btn = antd.Button("Send", type="primary", size="large")
|
|
|
|
| 907 |
execute_btn = antd.Button("Code ์คํ", type="default", size="large")
|
| 908 |
-
deploy_btn = antd.Button("๋ฐฐํฌํ๊ธฐ", type="default", size="large")
|
| 909 |
clear_btn = antd.Button("Clear", type="default", size="large")
|
| 910 |
|
|
|
|
|
|
|
|
|
|
| 911 |
# ๋ฐฐํฌ ๊ฒฐ๊ณผ๋ฅผ ํ์ํ ํ
์คํธ ์์ญ ์ถ๊ฐ
|
| 912 |
|
| 913 |
deploy_result = gr.HTML(label="๋ฐฐํฌ ๊ฒฐ๊ณผ")
|
|
@@ -1024,7 +1089,12 @@ with gr.Blocks(css_paths="app.css",theme=theme) as demo:
|
|
| 1024 |
outputs=[history]
|
| 1025 |
)
|
| 1026 |
|
| 1027 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1028 |
|
| 1029 |
# ์ด๋ฒคํธ ํธ๋ค๋ฌ ์์
|
| 1030 |
deploy_btn.click(
|
|
|
|
| 755 |
letters = string.ascii_lowercase
|
| 756 |
return ''.join(random.choice(letters) for i in range(6))
|
| 757 |
|
|
|
|
| 758 |
def deploy_to_vercel(code: str):
|
|
|
|
| 759 |
try:
|
| 760 |
token = "A8IFZmgW2cqA4yUNlLPnci0N"
|
| 761 |
if not token:
|
| 762 |
return "Vercel ํ ํฐ์ด ์ค์ ๋์ง ์์์ต๋๋ค."
|
| 763 |
|
| 764 |
+
# 6์๋ฆฌ ์๋ฌธ ํ๋ก์ ํธ ์ด๋ฆ ์์ฑ
|
| 765 |
project_name = ''.join(random.choice(string.ascii_lowercase) for i in range(6))
|
| 766 |
|
| 767 |
+
|
| 768 |
# Vercel API ์๋ํฌ์ธํธ
|
| 769 |
deploy_url = "https://api.vercel.com/v13/deployments"
|
| 770 |
|
|
|
|
| 817 |
"projectSettings": project_settings
|
| 818 |
}
|
| 819 |
|
| 820 |
+
|
| 821 |
deploy_response = requests.post(deploy_url, headers=headers, json=deploy_data)
|
| 822 |
|
| 823 |
if deploy_response.status_code != 200:
|
| 824 |
return f"๋ฐฐํฌ ์คํจ: {deploy_response.text}"
|
| 825 |
|
| 826 |
+
# URL ํ์ ์์ - 6์๋ฆฌ.vercel.app ํํ๋ก ๋ฐํ
|
| 827 |
+
deployment_url = f"{project_name}.vercel.app"
|
|
|
|
| 828 |
|
| 829 |
+
time.sleep(5)
|
|
|
|
| 830 |
|
| 831 |
+
return f"""๋ฐฐํฌ ์๋ฃ! <a href="https://{deployment_url}" target="_blank" style="color: #1890ff; text-decoration: underline; cursor: pointer;">https://{deployment_url}</a>"""
|
| 832 |
|
| 833 |
except Exception as e:
|
| 834 |
return f"๋ฐฐํฌ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
| 835 |
|
| 836 |
+
|
| 837 |
+
# ํ๋กฌํํธ ์ฆ๊ฐ ํจ์ ์์
|
| 838 |
+
async def boost_prompt(prompt: str) -> str:
|
| 839 |
+
if not prompt:
|
| 840 |
+
return ""
|
| 841 |
+
|
| 842 |
+
# ์ฆ๊ฐ์ ์ํ ์์คํ
ํ๋กฌํํธ
|
| 843 |
+
boost_system_prompt = """
|
| 844 |
+
๋น์ ์ ์น ๊ฐ๋ฐ ํ๋กฌํํธ ์ ๋ฌธ๊ฐ์
๋๋ค.
|
| 845 |
+
์ฃผ์ด์ง ํ๋กฌํํธ๋ฅผ ๋ถ์ํ์ฌ ๋ ์์ธํ๊ณ ์ ๋ฌธ์ ์ธ ์๊ตฌ์ฌํญ์ผ๋ก ํ์ฅํ๋,
|
| 846 |
+
์๋ ์๋์ ๋ชฉ์ ์ ๊ทธ๋๋ก ์ ์งํ๋ฉด์ ๋ค์ ๊ด์ ๋ค์ ๊ณ ๋ คํ์ฌ ์ฆ๊ฐํ์ญ์์ค:
|
| 847 |
+
|
| 848 |
+
1. ๊ธฐ์ ์ ๊ตฌํ ์์ธ
|
| 849 |
+
2. UI/UX ๋์์ธ ์์
|
| 850 |
+
3. ์ฌ์ฉ์ ๊ฒฝํ ์ต์ ํ
|
| 851 |
+
4. ์ฑ๋ฅ๊ณผ ๋ณด์
|
| 852 |
+
5. ์ ๊ทผ์ฑ๊ณผ ํธํ์ฑ
|
| 853 |
+
|
| 854 |
+
๊ธฐ์กด SystemPrompt์ ๋ชจ๋ ๊ท์น์ ์ค์ํ๋ฉด์ ์ฆ๊ฐ๋ ํ๋กฌํํธ๋ฅผ ์์ฑํ์ญ์์ค.
|
| 855 |
+
"""
|
| 856 |
+
|
| 857 |
+
try:
|
| 858 |
+
# Claude API ์๋
|
| 859 |
+
try:
|
| 860 |
+
response = await claude_client.messages.create(
|
| 861 |
+
model="claude-3-5-sonnet-20241022",
|
| 862 |
+
max_tokens=2000,
|
| 863 |
+
system=boost_system_prompt,
|
| 864 |
+
messages=[{
|
| 865 |
+
"role": "user",
|
| 866 |
+
"content": f"๋ค์ ํ๋กฌํํธ๋ฅผ ๋ถ์ํ๊ณ ์ฆ๊ฐํ์์ค: {prompt}"
|
| 867 |
+
}]
|
| 868 |
+
)
|
| 869 |
+
return response.content[0].text
|
| 870 |
+
|
| 871 |
+
except Exception as claude_error:
|
| 872 |
+
print(f"Claude API ์๋ฌ, OpenAI๋ก ์ ํ: {str(claude_error)}")
|
| 873 |
+
|
| 874 |
+
# OpenAI API ์๋
|
| 875 |
+
response = await openai_client.chat.completions.create(
|
| 876 |
+
model="gpt-4",
|
| 877 |
+
messages=[
|
| 878 |
+
{"role": "system", "content": boost_system_prompt},
|
| 879 |
+
{"role": "user", "content": f"๋ค์ ํ๋กฌํํธ๋ฅผ ๋ถ์ํ๊ณ ์ฆ๊ฐํ์์ค: {prompt}"}
|
| 880 |
+
],
|
| 881 |
+
max_tokens=2000,
|
| 882 |
+
temperature=0.7
|
| 883 |
+
)
|
| 884 |
+
return response.choices[0].message.content
|
| 885 |
+
|
| 886 |
+
except Exception as e:
|
| 887 |
+
print(f"ํ๋กฌํํธ ์ฆ๊ฐ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}")
|
| 888 |
+
return prompt # ์ค๋ฅ ๋ฐ์์ ์๋ณธ ํ๋กฌํํธ ๋ฐํ
|
| 889 |
+
|
| 890 |
+
# Boost ๋ฒํผ ์ด๋ฒคํธ ํธ๋ค๋ฌ ์์
|
| 891 |
+
async def handle_boost(prompt: str):
|
| 892 |
+
try:
|
| 893 |
+
boosted_prompt = await boost_prompt(prompt)
|
| 894 |
+
return boosted_prompt, gr.update(active_key="empty")
|
| 895 |
+
except Exception as e:
|
| 896 |
+
print(f"Boost ์ฒ๋ฆฌ ์ค ์ค๋ฅ: {str(e)}")
|
| 897 |
+
return prompt, gr.update(active_key="empty")
|
| 898 |
+
|
| 899 |
+
|
| 900 |
+
|
| 901 |
|
| 902 |
# Demo ์ธ์คํด์ค ์์ฑ
|
| 903 |
demo_instance = Demo()
|
|
|
|
| 962 |
allow_clear=True,
|
| 963 |
placeholder=random.choice(DEMO_LIST)['description']
|
| 964 |
)
|
| 965 |
+
|
|
|
|
|
|
|
| 966 |
with antd.Flex(gap="small", justify="space-between"):
|
| 967 |
btn = antd.Button("Send", type="primary", size="large")
|
| 968 |
+
boost_btn = antd.Button("Boost", type="default", size="large") # Boost ๋ฒํผ ์ถ๊ฐ
|
| 969 |
execute_btn = antd.Button("Code ์คํ", type="default", size="large")
|
| 970 |
+
deploy_btn = antd.Button("๋ฐฐํฌํ๊ธฐ", type="default", size="large")
|
| 971 |
clear_btn = antd.Button("Clear", type="default", size="large")
|
| 972 |
|
| 973 |
+
deploy_result = gr.HTML(label="๋ฐฐํฌ ๊ฒฐ๊ณผ")
|
| 974 |
+
|
| 975 |
+
|
| 976 |
# ๋ฐฐํฌ ๊ฒฐ๊ณผ๋ฅผ ํ์ํ ํ
์คํธ ์์ญ ์ถ๊ฐ
|
| 977 |
|
| 978 |
deploy_result = gr.HTML(label="๋ฐฐํฌ ๊ฒฐ๊ณผ")
|
|
|
|
| 1089 |
outputs=[history]
|
| 1090 |
)
|
| 1091 |
|
| 1092 |
+
# UI์ Boost ๋ฒํผ ์ด๋ฒคํธ ์ฐ๊ฒฐ ์์
|
| 1093 |
+
boost_btn.click(
|
| 1094 |
+
fn=handle_boost,
|
| 1095 |
+
inputs=[input],
|
| 1096 |
+
outputs=[input, state_tab]
|
| 1097 |
+
)
|
| 1098 |
|
| 1099 |
# ์ด๋ฒคํธ ํธ๋ค๋ฌ ์์
|
| 1100 |
deploy_btn.click(
|