openfree commited on
Commit
9ce8650
·
verified ·
1 Parent(s): e072cf7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -49
app.py CHANGED
@@ -575,13 +575,6 @@ with gr.Blocks(css_paths=["app.css"], theme=theme) as demo:
575
  history = gr.State([])
576
  setting = gr.State({"system": SystemPrompt})
577
 
578
- deploy_status = gr.State({
579
- "is_deployed": False,
580
- "status": "",
581
- "url": "",
582
- "message": ""
583
- })
584
-
585
  with ms.Application() as app:
586
  with antd.ConfigProvider():
587
 
@@ -654,9 +647,8 @@ with gr.Blocks(css_paths=["app.css"], theme=theme) as demo:
654
  )
655
  gr.HTML('<div class="help-text">💡 원하는 게임의 설명을 입력하세요. 예: "테트리스 게임 제작해줘."</div>')
656
 
657
- # 배포 결과 표시 - 수정된 부분
658
- deploy_status_text = gr.Markdown("", elem_id="deploy-status-text")
659
- deploy_url_link = gr.HTML("", elem_id="deploy-url-link")
660
 
661
  # 더 이상 자바스크립트 삽입 없음
662
  js_trigger = gr.HTML(elem_id="js-trigger", visible=False)
@@ -722,53 +714,75 @@ with gr.Blocks(css_paths=["app.css"], theme=theme) as demo:
722
  outputs=[sandbox, state_tab]
723
  )
724
 
725
- # 수정된 handle_deploy 함수 - 비동기 제너레이터 대신 일반 함수로 변경
726
- def handle_deploy(code, deploy_status):
727
- if not code:
728
- return "⚠️ **배포 실패**: 배포할 코드가 없습니다.", "", {
729
- "is_deployed": False,
730
- "status": "error",
731
- "message": "배포할 코드가 없습니다.",
732
- "url": ""
733
- }
734
 
735
  try:
736
  clean_code = remove_code_block(code)
737
- result = deploy_to_vercel(clean_code)
738
 
739
- if result.get("status") == "success":
740
- url = result.get("url", "")
741
- url_html = f'<a href="{url}" target="_blank" class="deploy-url">{url}</a>'
742
- return "✅ **배포 완료!** 아래 주소에서 게임을 확인할 수 있습니다:", url_html, {
743
- "is_deployed": True,
744
- "status": "success",
745
- "url": url,
746
- "message": "배포 완료!"
747
- }
748
- else:
749
- error_msg = result.get("message", "알 수 없는 오류")
750
- return f"⚠️ **배포 실패**: {error_msg}", "", {
751
- "is_deployed": False,
752
- "status": "error",
753
- "message": error_msg,
754
- "url": ""
 
 
 
755
  }
756
- except Exception as e:
757
- err = str(e)
758
- return f"⚠️ **시스템 오류**: {err}", "", {
759
- "is_deployed": False,
760
- "status": "error",
761
- "message": err,
762
- "url": ""
763
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
764
 
765
- # 수정된 배포 버튼 이벤트
766
  deploy_btn.click(
767
- fn=handle_deploy,
768
- inputs=[code_output, deploy_status],
769
- outputs=[deploy_status_text, deploy_url_link, deploy_status],
770
- api_name="deploy",
771
- queue=True
772
  )
773
  # ------------------------
774
  # 8) 실제 실행
 
575
  history = gr.State([])
576
  setting = gr.State({"system": SystemPrompt})
577
 
 
 
 
 
 
 
 
578
  with ms.Application() as app:
579
  with antd.ConfigProvider():
580
 
 
647
  )
648
  gr.HTML('<div class="help-text">💡 원하는 게임의 설명을 입력하세요. 예: "테트리스 게임 제작해줘."</div>')
649
 
650
+ # 가장 기본적인 방식의 배포 결과 표시
651
+ deploy_result = gr.Markdown("", label="배포 결과")
 
652
 
653
  # 더 이상 자바스크립트 삽입 없음
654
  js_trigger = gr.HTML(elem_id="js-trigger", visible=False)
 
714
  outputs=[sandbox, state_tab]
715
  )
716
 
717
+ # 매우 단순화된 배포 함수
718
+ def simple_deploy(code):
719
+ if not code or code.strip() == "":
720
+ return "⚠️ **배포 실패**: 배포할 코드가 없습니다. 먼저 게임을 생성해주세요."
 
 
 
 
 
721
 
722
  try:
723
  clean_code = remove_code_block(code)
 
724
 
725
+ token = "A8IFZmgW2cqA4yUNlLPnci0N"
726
+ if not token:
727
+ return "⚠️ **배포 실패**: Vercel 토큰이 설정되지 않았습니다."
728
+
729
+ project_name = ''.join(random.choice(string.ascii_lowercase) for i in range(6))
730
+ deploy_url = "https://api.vercel.com/v13/deployments"
731
+ headers = {
732
+ "Authorization": f"Bearer {token}",
733
+ "Content-Type": "application/json"
734
+ }
735
+ package_json = {
736
+ "name": project_name,
737
+ "version": "1.0.0",
738
+ "private": True,
739
+ "dependencies": {"vite": "^5.0.0"},
740
+ "scripts": {
741
+ "dev": "vite",
742
+ "build": "echo 'No build needed' && mkdir -p dist && cp index.html dist/",
743
+ "preview": "vite preview"
744
  }
 
 
 
 
 
 
 
745
  }
746
+ files = [
747
+ {"file": "index.html", "data": clean_code},
748
+ {"file": "package.json", "data": json.dumps(package_json, indent=2)}
749
+ ]
750
+ project_settings = {
751
+ "buildCommand": "npm run build",
752
+ "outputDirectory": "dist",
753
+ "installCommand": "npm install",
754
+ "framework": None
755
+ }
756
+ deploy_data = {
757
+ "name": project_name,
758
+ "files": files,
759
+ "target": "production",
760
+ "projectSettings": project_settings
761
+ }
762
+
763
+ deploy_response = requests.post(deploy_url, headers=headers, json=deploy_data)
764
+
765
+ if deploy_response.status_code != 200:
766
+ return f"⚠️ **배포 실패**: API 오류가 발생했습니다. (상태 코드: {deploy_response.status_code})"
767
+
768
+ time.sleep(5) # 배포 완료 대기
769
+
770
+ deployment_url = f"https://{project_name}.vercel.app"
771
+ return f"""✅ **배포 완료!**
772
+
773
+ 게임은 다음 주소에서 확인할 수 있습니다:
774
+ [{deployment_url}]({deployment_url})
775
+
776
+ 이 링크를 클릭하여 게임을 플레이하세요."""
777
+
778
+ except Exception as e:
779
+ return f"⚠️ **배포 실패**: {str(e)}"
780
 
781
+ # 배포 버튼 이벤트 - 가장 단순한 방식
782
  deploy_btn.click(
783
+ fn=simple_deploy,
784
+ inputs=[code_output],
785
+ outputs=[deploy_result]
 
 
786
  )
787
  # ------------------------
788
  # 8) 실제 실행