Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -650,27 +650,33 @@ class Demo:
|
|
650 |
# ------------------------
|
651 |
# 7) 실제 배포 함수를 수정하여 화면 표시
|
652 |
# ------------------------
|
653 |
-
|
654 |
def deploy_to_vercel(code: str):
|
|
|
|
|
655 |
try:
|
656 |
if not code or len(code.strip()) < 10:
|
657 |
-
|
658 |
return """
|
659 |
<div style='color:red; padding:10px; border:1px solid red; border-radius:5px;'>
|
660 |
배포할 코드가 없습니다. 먼저 게임 코드를 생성해주세요.
|
661 |
</div>
|
|
|
662 |
"""
|
663 |
|
664 |
token = "A8IFZmgW2cqA4yUNlLPnci0N"
|
665 |
if not token:
|
|
|
666 |
return """
|
667 |
<div style='color:red; padding:10px; border:1px solid red; border-radius:5px;'>
|
668 |
Vercel 토큰이 설정되지 않았습니다.
|
669 |
</div>
|
|
|
670 |
"""
|
671 |
|
672 |
project_name = ''.join(random.choice(string.ascii_lowercase) for i in range(6))
|
673 |
deploy_url = "https://api.vercel.com/v13/deployments"
|
|
|
|
|
674 |
headers = {
|
675 |
"Authorization": f"Bearer {token}",
|
676 |
"Content-Type": "application/json"
|
@@ -703,18 +709,24 @@ def deploy_to_vercel(code: str):
|
|
703 |
"projectSettings": project_settings
|
704 |
}
|
705 |
|
|
|
706 |
deploy_response = requests.post(deploy_url, headers=headers, json=deploy_data)
|
|
|
|
|
|
|
707 |
if deploy_response.status_code != 200:
|
708 |
return f"""
|
709 |
<div style='color:red; padding:10px; border:1px solid red; border-radius:5px;'>
|
710 |
배포 실패: {html.escape(deploy_response.text)}
|
711 |
</div>
|
|
|
712 |
"""
|
713 |
|
714 |
deployment_url = f"https://{project_name}.vercel.app"
|
|
|
715 |
time.sleep(3)
|
716 |
|
717 |
-
|
718 |
<div style='padding: 15px; background-color: #f0fff4; border: 1px solid #34c759; border-radius: 8px;'>
|
719 |
<h3 style='margin-top: 0; color: #34c759;'>✅ 배포 완료!</h3>
|
720 |
<p>게임이 성공적으로 배포되었습니다.</p>
|
@@ -724,6 +736,7 @@ def deploy_to_vercel(code: str):
|
|
724 |
</div>
|
725 |
</div>
|
726 |
<script>
|
|
|
727 |
showDeployBanner('success','✅ 배포 완료!','게임이 성공적으로 배포되었습니다.','{deployment_url}');
|
728 |
document.getElementById('deploy-result-box').innerHTML = `
|
729 |
<div class="deploy-success">
|
@@ -737,12 +750,17 @@ def deploy_to_vercel(code: str):
|
|
737 |
`;
|
738 |
</script>
|
739 |
"""
|
|
|
|
|
|
|
740 |
except Exception as e:
|
|
|
741 |
return f"""
|
742 |
<div style='color:red; padding:10px; border:1px solid red; border-radius:5px;'>
|
743 |
오류 발생: {html.escape(str(e))}
|
744 |
</div>
|
745 |
<script>
|
|
|
746 |
showDeployBanner('error','⚠️ 시스템 오류','{html.escape(str(e))}');
|
747 |
</script>
|
748 |
"""
|
@@ -752,15 +770,13 @@ def deploy_to_vercel(code: str):
|
|
752 |
# "handle_deploy" 수정: 실제로 사용하여 결과 표시
|
753 |
# ------------------------
|
754 |
def handle_deploy(code, deploy_status):
|
755 |
-
""
|
756 |
-
|
757 |
-
|
758 |
-
2) 실제 deploy_to_vercel() 실행 후 성공/실패 결과 HTML 반환
|
759 |
-
"""
|
760 |
if not code:
|
761 |
-
# 코드가 없는 경우 즉시 에러 메시지
|
762 |
js_code = """
|
763 |
<script>
|
|
|
764 |
showDeployBanner('error', '⚠️ 배포 실패', '배포할 코드가 없습니다. 먼저 게임 코드를 생성해주세요.');
|
765 |
document.getElementById('deploy-result-box').innerHTML = `
|
766 |
<div class="deploy-error">
|
@@ -770,6 +786,7 @@ def handle_deploy(code, deploy_status):
|
|
770 |
`;
|
771 |
</script>
|
772 |
"""
|
|
|
773 |
return js_code, {
|
774 |
"is_deployed": False,
|
775 |
"status": "error",
|
@@ -778,39 +795,41 @@ def handle_deploy(code, deploy_status):
|
|
778 |
}
|
779 |
|
780 |
try:
|
781 |
-
#
|
782 |
-
|
783 |
-
|
784 |
-
showDeployBanner('loading', '🔄 배포 진행 중', 'Vercel에 게임을 배포하고 있습니다. 잠시만 기다려주세요.');
|
785 |
-
document.getElementById('deploy-result-box').innerHTML = `
|
786 |
-
<div class="deploy-loading">
|
787 |
-
<div class="loading-spinner"></div>
|
788 |
-
<div class="loading-message">Vercel에 배포 중입니다...</div>
|
789 |
-
</div>
|
790 |
-
`;
|
791 |
-
</script>
|
792 |
-
"""
|
793 |
-
# Gradio에서는 "yield"를 사용하면 스트리밍 가능하지만,
|
794 |
-
# 간단히 한 번에 반환해도 됨. 여기서는 예시로 스트리밍 없이 진행.
|
795 |
-
# yield loading_js, deploy_status
|
796 |
|
797 |
-
# 2) 실제 배포 실행
|
798 |
clean_code = remove_code_block(code)
|
|
|
|
|
|
|
|
|
799 |
result_html = deploy_to_vercel(clean_code)
|
|
|
|
|
800 |
|
801 |
-
#
|
802 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
803 |
if "✅ 배포 완료!" in result_html:
|
804 |
-
|
805 |
-
return
|
806 |
"is_deployed": True,
|
807 |
"status": "success",
|
808 |
"url": "",
|
809 |
"message": "배포 성공"
|
810 |
}
|
811 |
else:
|
812 |
-
|
813 |
-
return
|
814 |
"is_deployed": False,
|
815 |
"status": "error",
|
816 |
"url": "",
|
@@ -819,8 +838,10 @@ def handle_deploy(code, deploy_status):
|
|
819 |
|
820 |
except Exception as e:
|
821 |
error_msg = str(e)
|
|
|
822 |
exception_js = f"""
|
823 |
<script>
|
|
|
824 |
showDeployBanner('error', '⚠️ 시스템 오류', '{error_msg}');
|
825 |
document.getElementById('deploy-result-box').innerHTML = `
|
826 |
<div class="deploy-error">
|
@@ -837,7 +858,6 @@ def handle_deploy(code, deploy_status):
|
|
837 |
"url": ""
|
838 |
}
|
839 |
|
840 |
-
|
841 |
# ------------------------
|
842 |
# 8) Gradio / Modelscope UI 빌드
|
843 |
# ------------------------
|
|
|
650 |
# ------------------------
|
651 |
# 7) 실제 배포 함수를 수정하여 화면 표시
|
652 |
# ------------------------
|
|
|
653 |
def deploy_to_vercel(code: str):
|
654 |
+
print("[DEBUG] deploy_to_vercel() 시작. code 길이:", len(code) if code else 0)
|
655 |
+
|
656 |
try:
|
657 |
if not code or len(code.strip()) < 10:
|
658 |
+
print("[DEBUG] code가 짧아서 배포할 수 없음.")
|
659 |
return """
|
660 |
<div style='color:red; padding:10px; border:1px solid red; border-radius:5px;'>
|
661 |
배포할 코드가 없습니다. 먼저 게임 코드를 생성해주세요.
|
662 |
</div>
|
663 |
+
<script>console.log('[DEBUG] 배포 실패: code가 너무 짧습니다.');</script>
|
664 |
"""
|
665 |
|
666 |
token = "A8IFZmgW2cqA4yUNlLPnci0N"
|
667 |
if not token:
|
668 |
+
print("[DEBUG] Vercel 토큰이 없음.")
|
669 |
return """
|
670 |
<div style='color:red; padding:10px; border:1px solid red; border-radius:5px;'>
|
671 |
Vercel 토큰이 설정되지 않았습니다.
|
672 |
</div>
|
673 |
+
<script>console.log('[DEBUG] 배포 실패: Vercel 토큰 없음');</script>
|
674 |
"""
|
675 |
|
676 |
project_name = ''.join(random.choice(string.ascii_lowercase) for i in range(6))
|
677 |
deploy_url = "https://api.vercel.com/v13/deployments"
|
678 |
+
print(f"[DEBUG] 생성된 project_name: {project_name}")
|
679 |
+
|
680 |
headers = {
|
681 |
"Authorization": f"Bearer {token}",
|
682 |
"Content-Type": "application/json"
|
|
|
709 |
"projectSettings": project_settings
|
710 |
}
|
711 |
|
712 |
+
print("[DEBUG] Vercel API 요청 전송중...")
|
713 |
deploy_response = requests.post(deploy_url, headers=headers, json=deploy_data)
|
714 |
+
print("[DEBUG] 응답 status_code:", deploy_response.status_code)
|
715 |
+
print("[DEBUG] 응답 body:", deploy_response.text[:300], "..." if len(deploy_response.text) > 300 else "")
|
716 |
+
|
717 |
if deploy_response.status_code != 200:
|
718 |
return f"""
|
719 |
<div style='color:red; padding:10px; border:1px solid red; border-radius:5px;'>
|
720 |
배포 실패: {html.escape(deploy_response.text)}
|
721 |
</div>
|
722 |
+
<script>console.log('[DEBUG] 배포 실패: {html.escape(deploy_response.text)}');</script>
|
723 |
"""
|
724 |
|
725 |
deployment_url = f"https://{project_name}.vercel.app"
|
726 |
+
print("[DEBUG] 배포 성공 추정. 3초 대기 후 최종 안내...")
|
727 |
time.sleep(3)
|
728 |
|
729 |
+
success_html = f"""
|
730 |
<div style='padding: 15px; background-color: #f0fff4; border: 1px solid #34c759; border-radius: 8px;'>
|
731 |
<h3 style='margin-top: 0; color: #34c759;'>✅ 배포 완료!</h3>
|
732 |
<p>게임이 성공적으로 배포되었습니다.</p>
|
|
|
736 |
</div>
|
737 |
</div>
|
738 |
<script>
|
739 |
+
console.log('[DEBUG] 배포 성공, deployment_url: {deployment_url}');
|
740 |
showDeployBanner('success','✅ 배포 완료!','게임이 성공적으로 배포되었습니다.','{deployment_url}');
|
741 |
document.getElementById('deploy-result-box').innerHTML = `
|
742 |
<div class="deploy-success">
|
|
|
750 |
`;
|
751 |
</script>
|
752 |
"""
|
753 |
+
print("[DEBUG] 최종 리턴 HTML 생성 완료")
|
754 |
+
return success_html
|
755 |
+
|
756 |
except Exception as e:
|
757 |
+
print("[ERROR] deploy_to_vercel() 예외:", e)
|
758 |
return f"""
|
759 |
<div style='color:red; padding:10px; border:1px solid red; border-radius:5px;'>
|
760 |
오류 발생: {html.escape(str(e))}
|
761 |
</div>
|
762 |
<script>
|
763 |
+
console.log('[DEBUG] deploy_to_vercel 내부 예외: {html.escape(str(e))}');
|
764 |
showDeployBanner('error','⚠️ 시스템 오류','{html.escape(str(e))}');
|
765 |
</script>
|
766 |
"""
|
|
|
770 |
# "handle_deploy" 수정: 실제로 사용하여 결과 표시
|
771 |
# ------------------------
|
772 |
def handle_deploy(code, deploy_status):
|
773 |
+
print("[DEBUG] handle_deploy() 함수가 호출되었습니다.")
|
774 |
+
print("[DEBUG] 전달된 code:", repr(code[:300] if code else code)) # 코드 일부만 출력
|
775 |
+
|
|
|
|
|
776 |
if not code:
|
|
|
777 |
js_code = """
|
778 |
<script>
|
779 |
+
console.log('[DEBUG] 배포할 코드가 없어 에러 처리');
|
780 |
showDeployBanner('error', '⚠️ 배포 실패', '배포할 코드가 없습니다. 먼저 게임 코드를 생성해주세요.');
|
781 |
document.getElementById('deploy-result-box').innerHTML = `
|
782 |
<div class="deploy-error">
|
|
|
786 |
`;
|
787 |
</script>
|
788 |
"""
|
789 |
+
print("[DEBUG] code가 없으므로 에러 HTML 반환")
|
790 |
return js_code, {
|
791 |
"is_deployed": False,
|
792 |
"status": "error",
|
|
|
795 |
}
|
796 |
|
797 |
try:
|
798 |
+
# 로딩 상태 표시
|
799 |
+
# (스트리밍을 쓰지 않고, 한꺼번에 HTML 반환)
|
800 |
+
print("[DEBUG] 배포 로딩 상태 HTML 생성 중...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
801 |
|
|
|
802 |
clean_code = remove_code_block(code)
|
803 |
+
print("[DEBUG] remove_code_block 후 clean_code 길이:", len(clean_code))
|
804 |
+
|
805 |
+
# 실제 배포
|
806 |
+
print("[DEBUG] deploy_to_vercel() 호출 시작")
|
807 |
result_html = deploy_to_vercel(clean_code)
|
808 |
+
print("[DEBUG] deploy_to_vercel() 결과 수신:")
|
809 |
+
print(result_html[:500], "..." if len(result_html) > 500 else "")
|
810 |
|
811 |
+
# 브라우저 console.log로도 표시
|
812 |
+
debug_injection = """
|
813 |
+
<script>
|
814 |
+
console.log('[DEBUG] 배포 후 결과 HTML:', %s);
|
815 |
+
</script>
|
816 |
+
""" % (json.dumps(result_html[:300]) if len(result_html) > 300 else json.dumps(result_html))
|
817 |
+
|
818 |
+
# 배포 결과를 종합한 HTML
|
819 |
+
final_html = result_html + debug_injection
|
820 |
+
|
821 |
+
# 성공/실패 판단
|
822 |
if "✅ 배포 완료!" in result_html:
|
823 |
+
print("[DEBUG] 배포 성공으로 판단")
|
824 |
+
return final_html, {
|
825 |
"is_deployed": True,
|
826 |
"status": "success",
|
827 |
"url": "",
|
828 |
"message": "배포 성공"
|
829 |
}
|
830 |
else:
|
831 |
+
print("[DEBUG] 배포 실패 또는 오류")
|
832 |
+
return final_html, {
|
833 |
"is_deployed": False,
|
834 |
"status": "error",
|
835 |
"url": "",
|
|
|
838 |
|
839 |
except Exception as e:
|
840 |
error_msg = str(e)
|
841 |
+
print("[ERROR] handle_deploy에서 예외 발생:", error_msg)
|
842 |
exception_js = f"""
|
843 |
<script>
|
844 |
+
console.log('[DEBUG] handle_deploy 예외: {error_msg}');
|
845 |
showDeployBanner('error', '⚠️ 시스템 오류', '{error_msg}');
|
846 |
document.getElementById('deploy-result-box').innerHTML = `
|
847 |
<div class="deploy-error">
|
|
|
858 |
"url": ""
|
859 |
}
|
860 |
|
|
|
861 |
# ------------------------
|
862 |
# 8) Gradio / Modelscope UI 빌드
|
863 |
# ------------------------
|