openfree commited on
Commit
b609ab4
·
verified ·
1 Parent(s): 797b500

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -52
app.py CHANGED
@@ -1020,23 +1020,24 @@ with gr.Blocks(css_paths=["app.css"], theme=theme) as demo:
1020
 
1021
  def deploy_to_vercel(code: str):
1022
  try:
1023
- token = "A8IFZmgW2cqA4yUNlLPnci0N" # 실제 토큰 필요
 
 
 
1024
  if not token:
1025
- return """
1026
- <div class="deploy-section">
1027
- <div class="deploy-error">
1028
- <div class="error-icon">⚠️</div>
1029
- <div class="error-message">Vercel 토큰이 설정되지 않았습니다.</div>
1030
- </div>
1031
- </div>
1032
- """
1033
-
1034
  project_name = ''.join(random.choice(string.ascii_lowercase) for i in range(6))
 
 
1035
  deploy_url = "https://api.vercel.com/v13/deployments"
1036
  headers = {
1037
  "Authorization": f"Bearer {token}",
1038
  "Content-Type": "application/json"
1039
  }
 
 
1040
  package_json = {
1041
  "name": project_name,
1042
  "version": "1.0.0",
@@ -1048,59 +1049,53 @@ with gr.Blocks(css_paths=["app.css"], theme=theme) as demo:
1048
  "preview": "vite preview"
1049
  }
1050
  }
 
 
1051
  files = [
1052
  {"file": "index.html", "data": code},
1053
  {"file": "package.json", "data": json.dumps(package_json, indent=2)}
1054
  ]
 
 
1055
  project_settings = {
1056
  "buildCommand": "npm run build",
1057
  "outputDirectory": "dist",
1058
  "installCommand": "npm install",
1059
  "framework": None
1060
  }
 
 
1061
  deploy_data = {
1062
  "name": project_name,
1063
  "files": files,
1064
  "target": "production",
1065
  "projectSettings": project_settings
1066
  }
 
 
1067
  deploy_response = requests.post(deploy_url, headers=headers, json=deploy_data)
1068
  if deploy_response.status_code != 200:
1069
- return f"""
1070
- <div class="deploy-section">
1071
- <div class="deploy-error">
1072
- <div class="error-icon">⚠️</div>
1073
- <div class="error-message">배포 실패: {deploy_response.text}</div>
1074
- </div>
1075
- </div>
1076
- """
1077
 
 
1078
  deployment_url = f"https://{project_name}.vercel.app"
1079
- time.sleep(5)
1080
 
 
 
 
 
1081
  return f"""
1082
- <div class="deploy-section">
1083
- <div class="deploy-header">📤 배포 결과</div>
1084
- <div class="deploy-success">
1085
- <div class="success-icon">✅</div>
1086
- <div class="success-message">배포 완료!</div>
1087
- <div class="url-box">
1088
- <a href="{deployment_url}" target="_blank">{deployment_url}</a>
1089
- <button class="copy-btn" onclick="navigator.clipboard.writeText('{deployment_url}')">복사</button>
1090
- </div>
1091
- </div>
1092
- </div>
1093
- """
1094
  except Exception as e:
1095
- return f"""
1096
- <div class="deploy-section">
1097
- <div class="deploy-error">
1098
- <div class="error-icon">⚠️</div>
1099
- <div class="error-message">배포 중 오류 발생: {str(e)}</div>
1100
- </div>
1101
- </div>
1102
- """
1103
-
1104
 
1105
 
1106
  # handle_deploy
@@ -1204,21 +1199,12 @@ with gr.Blocks(css_paths=["app.css"], theme=theme) as demo:
1204
  "url": ""
1205
  }
1206
 
1207
-
1208
-
1209
  deploy_btn.click(
1210
- fn=lambda code: deploy_to_vercel(remove_code_block(code)) if code else """
1211
- <div class="deploy-section">
1212
- <div class="deploy-error">
1213
- <div class="error-icon">⚠️</div>
1214
- <div class="error-message">배포할 코드가 없습니다. 먼저 게임 코드를 생성해주세요.</div>
1215
- </div>
1216
- </div>
1217
- """,
1218
  inputs=[code_output],
1219
  outputs=[deploy_result_container]
1220
- )
1221
-
1222
  # ------------------------
1223
  # 8) 실제 실행
1224
  # ------------------------
 
1020
 
1021
  def deploy_to_vercel(code: str):
1022
  try:
1023
+ if not code or len(code.strip()) < 10:
1024
+ return "<div style='color:red; padding:10px; border:1px solid red; border-radius:5px;'>배포할 코드가 없습니다. 먼저 게임 코드를 생성해주세요.</div>"
1025
+
1026
+ token = "A8IFZmgW2cqA4yUNlLPnci0N"
1027
  if not token:
1028
+ return "<div style='color:red; padding:10px; border:1px solid red; border-radius:5px;'>Vercel 토큰이 설정되지 않았습니다.</div>"
1029
+
1030
+ # 프로젝트 이름 생성
 
 
 
 
 
 
1031
  project_name = ''.join(random.choice(string.ascii_lowercase) for i in range(6))
1032
+
1033
+ # Vercel API 요청 준비
1034
  deploy_url = "https://api.vercel.com/v13/deployments"
1035
  headers = {
1036
  "Authorization": f"Bearer {token}",
1037
  "Content-Type": "application/json"
1038
  }
1039
+
1040
+ # 패키지 정보
1041
  package_json = {
1042
  "name": project_name,
1043
  "version": "1.0.0",
 
1049
  "preview": "vite preview"
1050
  }
1051
  }
1052
+
1053
+ # 배포할 파일들
1054
  files = [
1055
  {"file": "index.html", "data": code},
1056
  {"file": "package.json", "data": json.dumps(package_json, indent=2)}
1057
  ]
1058
+
1059
+ # 프로젝트 설정
1060
  project_settings = {
1061
  "buildCommand": "npm run build",
1062
  "outputDirectory": "dist",
1063
  "installCommand": "npm install",
1064
  "framework": None
1065
  }
1066
+
1067
+ # 배포 데이터
1068
  deploy_data = {
1069
  "name": project_name,
1070
  "files": files,
1071
  "target": "production",
1072
  "projectSettings": project_settings
1073
  }
1074
+
1075
+ # API 요청 및 응답 처리
1076
  deploy_response = requests.post(deploy_url, headers=headers, json=deploy_data)
1077
  if deploy_response.status_code != 200:
1078
+ return f"<div style='color:red; padding:10px; border:1px solid red; border-radius:5px;'>배포 실패: {deploy_response.text}</div>"
 
 
 
 
 
 
 
1079
 
1080
+ # 배포 URL 생성
1081
  deployment_url = f"https://{project_name}.vercel.app"
 
1082
 
1083
+ # 배포 완료 기다리기
1084
+ time.sleep(3)
1085
+
1086
+ # 결과 반환
1087
  return f"""
1088
+ <div style='padding: 15px; background-color: #f0fff4; border: 1px solid #34c759; border-radius: 8px;'>
1089
+ <h3 style='margin-top: 0; color: #34c759;'>✅ 배포 완료!</h3>
1090
+ <p>게임이 성공적으로 배포되었습니다.</p>
1091
+ <div style='margin-top: 10px; padding: 10px; background: #f8fafc; border-radius: 6px; display: flex; justify-content: space-between; align-items: center;'>
1092
+ <a href="{deployment_url}" target="_blank" style='color: #0066cc; text-decoration: none; word-break: break-all;'>{deployment_url}</a>
1093
+ <button onclick="navigator.clipboard.writeText('{deployment_url}')" style='background: #0066cc; color: white; border: none; border-radius: 4px; padding: 5px 10px; cursor: pointer;'>복사</button>
1094
+ </div>
1095
+ </div>
1096
+ """
 
 
 
1097
  except Exception as e:
1098
+ return f"<div style='color:red; padding:10px; border:1px solid red; border-radius:5px;'>오류 발생: {str(e)}</div>"
 
 
 
 
 
 
 
 
1099
 
1100
 
1101
  # handle_deploy
 
1199
  "url": ""
1200
  }
1201
 
1202
+ # deploy_btn.click 함수를 찾아 다음으로 완전히 교체하세요
 
1203
  deploy_btn.click(
1204
+ fn=lambda code: deploy_to_vercel(remove_code_block(code)),
 
 
 
 
 
 
 
1205
  inputs=[code_output],
1206
  outputs=[deploy_result_container]
1207
+ )
 
1208
  # ------------------------
1209
  # 8) 실제 실행
1210
  # ------------------------