openfree commited on
Commit
74ab846
·
verified ·
1 Parent(s): 71c9fce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -10
app.py CHANGED
@@ -255,8 +255,6 @@ async def try_openai_api(openai_messages):
255
  raise e
256
 
257
 
258
-
259
-
260
  # ------------------------
261
  # 4) 템플릿(하나로 통합)
262
  # ------------------------
@@ -441,6 +439,8 @@ def load_all_templates():
441
  """
442
  return create_template_html("🎮 모든 게임 템플릿", load_json_data())
443
 
 
 
444
  def create_template_html(title, items):
445
  """
446
  이미지 없이 템플릿 HTML 생성
@@ -512,8 +512,12 @@ function copyToInput(card) {
512
  </div>
513
  """
514
  return gr.HTML(value=html_content)
515
-
516
 
 
 
 
 
 
517
 
518
 
519
  # ------------------------
@@ -526,12 +530,12 @@ def generate_space_name():
526
 
527
  def deploy_to_vercel(code: str):
528
  """
529
- Vercel에 배포하는 함수 (예시)
530
  """
531
  try:
532
  token = "A8IFZmgW2cqA4yUNlLPnci0N" # 실제 토큰 필요
533
  if not token:
534
- return "Vercel 토큰이 설정되지 않았습니다."
535
 
536
  project_name = ''.join(random.choice(string.ascii_lowercase) for i in range(6))
537
  deploy_url = "https://api.vercel.com/v13/deployments"
@@ -576,12 +580,25 @@ def deploy_to_vercel(code: str):
576
  }
577
  deploy_response = requests.post(deploy_url, headers=headers, json=deploy_data)
578
  if deploy_response.status_code != 200:
579
- return f"배포 실패: {deploy_response.text}"
 
580
  deployment_url = f"{project_name}.vercel.app"
581
  time.sleep(5)
582
- return f"""배포 완료! <a href="https://{deployment_url}" target="_blank" style="color: #1890ff; text-decoration: underline; cursor: pointer;">https://{deployment_url}</a>"""
 
 
 
 
 
 
 
 
 
 
 
 
583
  except Exception as e:
584
- return f"배포 중 오류 발생: {str(e)}"
585
 
586
  def remove_code_block(text):
587
  """
@@ -1077,7 +1094,9 @@ with gr.Blocks(css_paths=["app.css"], theme=theme) as demo:
1077
  gr.HTML('<div class="help-text">💡 원하는 게임의 설명을 입력하세요. 예: "테트리스 게임 제작해줘."</div>')
1078
 
1079
  # ── (4) 배포 결과 영역 ──
1080
- deploy_result = gr.HTML(label="배포 결과")
 
 
1081
 
1082
 
1083
  # ---- 이벤트 / 콜백 ----
@@ -1151,7 +1170,7 @@ with gr.Blocks(css_paths=["app.css"], theme=theme) as demo:
1151
 
1152
  # (H) '배포' 버튼 => Vercel
1153
  deploy_btn.click(
1154
- fn=lambda code: deploy_to_vercel(remove_code_block(code)) if code else "코드가 없습니다.",
1155
  inputs=[code_output],
1156
  outputs=[deploy_result]
1157
  )
 
255
  raise e
256
 
257
 
 
 
258
  # ------------------------
259
  # 4) 템플릿(하나로 통합)
260
  # ------------------------
 
439
  """
440
  return create_template_html("🎮 모든 게임 템플릿", load_json_data())
441
 
442
+
443
+
444
  def create_template_html(title, items):
445
  """
446
  이미지 없이 템플릿 HTML 생성
 
512
  </div>
513
  """
514
  return gr.HTML(value=html_content)
 
515
 
516
+ def load_all_templates():
517
+ """
518
+ 모든 템플릿을 하나로 보여주는 함수
519
+ """
520
+ return create_template_html("🎮 모든 게임 템플릿", load_json_data())
521
 
522
 
523
  # ------------------------
 
530
 
531
  def deploy_to_vercel(code: str):
532
  """
533
+ Vercel에 배포하는 함수 - 배포 결과 표시 개선
534
  """
535
  try:
536
  token = "A8IFZmgW2cqA4yUNlLPnci0N" # 실제 토큰 필요
537
  if not token:
538
+ return "<div class='deploy-error'>Vercel 토큰이 설정되지 않았습니다.</div>"
539
 
540
  project_name = ''.join(random.choice(string.ascii_lowercase) for i in range(6))
541
  deploy_url = "https://api.vercel.com/v13/deployments"
 
580
  }
581
  deploy_response = requests.post(deploy_url, headers=headers, json=deploy_data)
582
  if deploy_response.status_code != 200:
583
+ return f"<div class='deploy-error'>배포 실패: {deploy_response.text}</div>"
584
+
585
  deployment_url = f"{project_name}.vercel.app"
586
  time.sleep(5)
587
+
588
+ # 더 눈에 띄는 형식으로 URL 반환
589
+ return f"""
590
+ <div class='deploy-success'>
591
+ <div>✅ 배포가 완료되었습니다!</div>
592
+ <div class='deploy-url'>
593
+ <a href="https://{deployment_url}" target="_blank" rel="noopener noreferrer">
594
+ https://{deployment_url}
595
+ </a>
596
+ </div>
597
+ <div class='deploy-note'>위 링크를 클릭하여 배포된 게임을 확인하세요.</div>
598
+ </div>
599
+ """
600
  except Exception as e:
601
+ return f"<div class='deploy-error'>배포 중 오류 발생: {str(e)}</div>"
602
 
603
  def remove_code_block(text):
604
  """
 
1094
  gr.HTML('<div class="help-text">💡 원하는 게임의 설명을 입력하세요. 예: "테트리스 게임 제작해줘."</div>')
1095
 
1096
  # ── (4) 배포 결과 영역 ──
1097
+ with antd.Flex(vertical=True, gap="small", elem_classes="deploy-result-container"):
1098
+ gr.HTML('<div class="deploy-result-title">📤 배포 결과</div>')
1099
+ deploy_result = gr.HTML(elem_classes="deploy-result-box")
1100
 
1101
 
1102
  # ---- 이벤트 / 콜백 ----
 
1170
 
1171
  # (H) '배포' 버튼 => Vercel
1172
  deploy_btn.click(
1173
+ fn=lambda code: deploy_to_vercel(remove_code_block(code)) if code else "<div class='deploy-error'>코드가 없습니다.</div>",
1174
  inputs=[code_output],
1175
  outputs=[deploy_result]
1176
  )