Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -649,18 +649,20 @@ class Demo:
|
|
| 649 |
# 1) deploy_to_vercel 함수
|
| 650 |
####################################################
|
| 651 |
def deploy_to_vercel(code: str):
|
| 652 |
-
|
| 653 |
try:
|
| 654 |
if not code or len(code.strip()) < 10:
|
| 655 |
-
|
| 656 |
-
return "No code to deploy.
|
| 657 |
|
| 658 |
token = "A8IFZmgW2cqA4yUNlLPnci0N"
|
| 659 |
if not token:
|
| 660 |
-
|
| 661 |
return "Vercel token is not set."
|
| 662 |
|
| 663 |
project_name = ''.join(random.choice(string.ascii_lowercase) for _ in range(6))
|
|
|
|
|
|
|
| 664 |
deploy_url = "https://api.vercel.com/v13/deployments"
|
| 665 |
headers = {
|
| 666 |
"Authorization": f"Bearer {token}",
|
|
@@ -678,6 +680,7 @@ def deploy_to_vercel(code: str):
|
|
| 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)}
|
|
@@ -688,6 +691,7 @@ def deploy_to_vercel(code: str):
|
|
| 688 |
"installCommand": "npm install",
|
| 689 |
"framework": None
|
| 690 |
}
|
|
|
|
| 691 |
deploy_data = {
|
| 692 |
"name": project_name,
|
| 693 |
"files": files,
|
|
@@ -695,18 +699,19 @@ def deploy_to_vercel(code: str):
|
|
| 695 |
"projectSettings": project_settings
|
| 696 |
}
|
| 697 |
|
| 698 |
-
|
| 699 |
deploy_response = requests.post(deploy_url, headers=headers, json=deploy_data)
|
| 700 |
-
|
| 701 |
|
| 702 |
if deploy_response.status_code != 200:
|
| 703 |
-
|
| 704 |
return f"Deployment failed: {deploy_response.text}"
|
| 705 |
|
| 706 |
deployment_url = f"https://{project_name}.vercel.app"
|
| 707 |
-
|
| 708 |
time.sleep(3)
|
| 709 |
|
|
|
|
| 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>
|
|
@@ -720,10 +725,11 @@ def deploy_to_vercel(code: str):
|
|
| 720 |
"""
|
| 721 |
|
| 722 |
except Exception as e:
|
| 723 |
-
|
| 724 |
return f"Error during deployment: {str(e)}"
|
| 725 |
|
| 726 |
|
|
|
|
| 727 |
# ------------------------
|
| 728 |
# (3) handle_deploy_legacy
|
| 729 |
# ------------------------
|
|
@@ -755,7 +761,6 @@ def handle_deploy_legacy(code):
|
|
| 755 |
# ------------------------
|
| 756 |
# 8) Gradio / Modelscope UI 빌드
|
| 757 |
# ------------------------
|
| 758 |
-
|
| 759 |
demo_instance = Demo()
|
| 760 |
theme = gr.themes.Soft(
|
| 761 |
primary_hue="blue",
|
|
|
|
| 649 |
# 1) deploy_to_vercel 함수
|
| 650 |
####################################################
|
| 651 |
def deploy_to_vercel(code: str):
|
| 652 |
+
print(f"[DEBUG] deploy_to_vercel() 시작. code 길이: {len(code) if code else 0}")
|
| 653 |
try:
|
| 654 |
if not code or len(code.strip()) < 10:
|
| 655 |
+
print("[DEBUG] 배포 불가: code가 짧음")
|
| 656 |
+
return "No code to deploy."
|
| 657 |
|
| 658 |
token = "A8IFZmgW2cqA4yUNlLPnci0N"
|
| 659 |
if not token:
|
| 660 |
+
print("[DEBUG] Vercel 토큰이 없음.")
|
| 661 |
return "Vercel token is not set."
|
| 662 |
|
| 663 |
project_name = ''.join(random.choice(string.ascii_lowercase) for _ in range(6))
|
| 664 |
+
print(f"[DEBUG] 생성된 project_name: {project_name}")
|
| 665 |
+
|
| 666 |
deploy_url = "https://api.vercel.com/v13/deployments"
|
| 667 |
headers = {
|
| 668 |
"Authorization": f"Bearer {token}",
|
|
|
|
| 680 |
"preview": "vite preview"
|
| 681 |
}
|
| 682 |
}
|
| 683 |
+
|
| 684 |
files = [
|
| 685 |
{"file": "index.html", "data": code},
|
| 686 |
{"file": "package.json", "data": json.dumps(package_json, indent=2)}
|
|
|
|
| 691 |
"installCommand": "npm install",
|
| 692 |
"framework": None
|
| 693 |
}
|
| 694 |
+
|
| 695 |
deploy_data = {
|
| 696 |
"name": project_name,
|
| 697 |
"files": files,
|
|
|
|
| 699 |
"projectSettings": project_settings
|
| 700 |
}
|
| 701 |
|
| 702 |
+
print("[DEBUG] Vercel API 요청 전송중...")
|
| 703 |
deploy_response = requests.post(deploy_url, headers=headers, json=deploy_data)
|
| 704 |
+
print("[DEBUG] 응답 status_code:", deploy_response.status_code)
|
| 705 |
|
| 706 |
if deploy_response.status_code != 200:
|
| 707 |
+
print("[DEBUG] 배포 실패:", deploy_response.text)
|
| 708 |
return f"Deployment failed: {deploy_response.text}"
|
| 709 |
|
| 710 |
deployment_url = f"https://{project_name}.vercel.app"
|
| 711 |
+
print(f"[DEBUG] 배포 성공 -> URL: {deployment_url}")
|
| 712 |
time.sleep(3)
|
| 713 |
|
| 714 |
+
# 자바스크립트 없이, 링크만
|
| 715 |
return f"""
|
| 716 |
<div style="border:1px solid #34c759; padding:15px; border-radius:8px;">
|
| 717 |
<h3 style="margin:0; color:#34c759;">✅ Deployment complete!</h3>
|
|
|
|
| 725 |
"""
|
| 726 |
|
| 727 |
except Exception as e:
|
| 728 |
+
print("[ERROR] deploy_to_vercel() 예외:", e)
|
| 729 |
return f"Error during deployment: {str(e)}"
|
| 730 |
|
| 731 |
|
| 732 |
+
|
| 733 |
# ------------------------
|
| 734 |
# (3) handle_deploy_legacy
|
| 735 |
# ------------------------
|
|
|
|
| 761 |
# ------------------------
|
| 762 |
# 8) Gradio / Modelscope UI 빌드
|
| 763 |
# ------------------------
|
|
|
|
| 764 |
demo_instance = Demo()
|
| 765 |
theme = gr.themes.Soft(
|
| 766 |
primary_hue="blue",
|