Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -653,16 +653,13 @@ class Demo:
|
|
653 |
def deploy_to_vercel(code: str):
|
654 |
print("[DEBUG] deploy_to_vercel() 시작. code 길이:", len(code) if code else 0)
|
655 |
try:
|
656 |
-
# code 유효성 체크
|
657 |
if not code or len(code.strip()) < 10:
|
658 |
-
return "No code to deploy."
|
659 |
|
660 |
-
# 예시: Vercel 토큰
|
661 |
token = "A8IFZmgW2cqA4yUNlLPnci0N"
|
662 |
if not token:
|
663 |
return "Vercel token is not set."
|
664 |
|
665 |
-
# 프로젝트 이름
|
666 |
project_name = ''.join(random.choice(string.ascii_lowercase) for i in range(6))
|
667 |
deploy_url = "https://api.vercel.com/v13/deployments"
|
668 |
headers = {
|
@@ -681,19 +678,16 @@ def deploy_to_vercel(code: str):
|
|
681 |
"preview": "vite preview"
|
682 |
}
|
683 |
}
|
684 |
-
|
685 |
files = [
|
686 |
{"file": "index.html", "data": code},
|
687 |
{"file": "package.json", "data": json.dumps(package_json, indent=2)}
|
688 |
]
|
689 |
-
|
690 |
project_settings = {
|
691 |
"buildCommand": "npm run build",
|
692 |
"outputDirectory": "dist",
|
693 |
"installCommand": "npm install",
|
694 |
"framework": None
|
695 |
}
|
696 |
-
|
697 |
deploy_data = {
|
698 |
"name": project_name,
|
699 |
"files": files,
|
@@ -708,21 +702,19 @@ def deploy_to_vercel(code: str):
|
|
708 |
if deploy_response.status_code != 200:
|
709 |
return f"Deployment failed: {deploy_response.text}"
|
710 |
|
711 |
-
# 정상 배포 -> URL
|
712 |
deployment_url = f"https://{project_name}.vercel.app"
|
713 |
-
print("[DEBUG] 배포
|
714 |
time.sleep(3)
|
715 |
|
716 |
-
# ★
|
717 |
-
# ex) "Deployment complete! <a href='...' target='_blank'> ...</a>"
|
718 |
return f"""
|
719 |
-
<div style="border:1px solid #
|
720 |
-
<h3 style="color:#
|
721 |
<p style="margin:0;">
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
</p>
|
727 |
</div>
|
728 |
"""
|
@@ -731,8 +723,6 @@ def deploy_to_vercel(code: str):
|
|
731 |
print("[ERROR] deploy_to_vercel() 예외:", e)
|
732 |
return f"Error during deployment: {str(e)}"
|
733 |
|
734 |
-
|
735 |
-
|
736 |
####################################################
|
737 |
# 2) handle_deploy_legacy: iframe으로 결과 표시
|
738 |
####################################################
|
@@ -1119,21 +1109,14 @@ with gr.Blocks(css_paths=["app.css"], theme=theme) as demo:
|
|
1119 |
outputs=[sandbox, state_tab]
|
1120 |
)
|
1121 |
|
1122 |
-
|
1123 |
-
|
1124 |
-
|
1125 |
-
|
1126 |
-
|
1127 |
-
############################################################
|
1128 |
-
# 4) deploy_btn.click: handle_deploy_legacy를 호출
|
1129 |
-
############################################################
|
1130 |
deploy_btn.click(
|
1131 |
-
fn=
|
1132 |
-
inputs=[code_output],
|
1133 |
-
outputs=[
|
1134 |
)
|
1135 |
|
1136 |
|
|
|
1137 |
# ------------------------
|
1138 |
# 9) 실행
|
1139 |
# ------------------------
|
|
|
653 |
def deploy_to_vercel(code: str):
|
654 |
print("[DEBUG] deploy_to_vercel() 시작. code 길이:", len(code) if code else 0)
|
655 |
try:
|
|
|
656 |
if not code or len(code.strip()) < 10:
|
657 |
+
return "No code to deploy. (Code is empty)"
|
658 |
|
|
|
659 |
token = "A8IFZmgW2cqA4yUNlLPnci0N"
|
660 |
if not token:
|
661 |
return "Vercel token is not set."
|
662 |
|
|
|
663 |
project_name = ''.join(random.choice(string.ascii_lowercase) for i in range(6))
|
664 |
deploy_url = "https://api.vercel.com/v13/deployments"
|
665 |
headers = {
|
|
|
678 |
"preview": "vite preview"
|
679 |
}
|
680 |
}
|
|
|
681 |
files = [
|
682 |
{"file": "index.html", "data": code},
|
683 |
{"file": "package.json", "data": json.dumps(package_json, indent=2)}
|
684 |
]
|
|
|
685 |
project_settings = {
|
686 |
"buildCommand": "npm run build",
|
687 |
"outputDirectory": "dist",
|
688 |
"installCommand": "npm install",
|
689 |
"framework": None
|
690 |
}
|
|
|
691 |
deploy_data = {
|
692 |
"name": project_name,
|
693 |
"files": files,
|
|
|
702 |
if deploy_response.status_code != 200:
|
703 |
return f"Deployment failed: {deploy_response.text}"
|
704 |
|
|
|
705 |
deployment_url = f"https://{project_name}.vercel.app"
|
706 |
+
print("[DEBUG] 배포 성공, 배포 URL:", deployment_url)
|
707 |
time.sleep(3)
|
708 |
|
709 |
+
# ★ 원본 코드 스타일: 심플 HTML (스크립트/iframe 없이)
|
|
|
710 |
return f"""
|
711 |
+
<div style="border:1px solid #34c759; padding:15px; border-radius:8px;">
|
712 |
+
<h3 style="margin:0; color:#34c759;">✅ Deployment complete!</h3>
|
713 |
<p style="margin:0;">
|
714 |
+
Your app is live at:
|
715 |
+
<a href="{deployment_url}" target="_blank" style="color: #0066cc; text-decoration: underline;">
|
716 |
+
{deployment_url}
|
717 |
+
</a>
|
718 |
</p>
|
719 |
</div>
|
720 |
"""
|
|
|
723 |
print("[ERROR] deploy_to_vercel() 예외:", e)
|
724 |
return f"Error during deployment: {str(e)}"
|
725 |
|
|
|
|
|
726 |
####################################################
|
727 |
# 2) handle_deploy_legacy: iframe으로 결과 표시
|
728 |
####################################################
|
|
|
1109 |
outputs=[sandbox, state_tab]
|
1110 |
)
|
1111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1112 |
deploy_btn.click(
|
1113 |
+
fn=lambda code: deploy_to_vercel(remove_code_block(code)) if code else "No code generated.",
|
1114 |
+
inputs=[code_output],
|
1115 |
+
outputs=[deploy_result]
|
1116 |
)
|
1117 |
|
1118 |
|
1119 |
+
|
1120 |
# ------------------------
|
1121 |
# 9) 실행
|
1122 |
# ------------------------
|