Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -650,9 +650,11 @@ class Demo:
|
|
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가 짧아서 배포할 수 없음.")
|
@@ -662,7 +664,7 @@ def deploy_to_vercel(code: str):
|
|
662 |
</div>
|
663 |
<script>console.log('[DEBUG] 배포 실패: code가 너무 짧습니다.');</script>
|
664 |
"""
|
665 |
-
|
666 |
token = "A8IFZmgW2cqA4yUNlLPnci0N"
|
667 |
if not token:
|
668 |
print("[DEBUG] Vercel 토큰이 없음.")
|
@@ -672,7 +674,7 @@ def deploy_to_vercel(code: str):
|
|
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}")
|
@@ -708,12 +710,12 @@ def deploy_to_vercel(code: str):
|
|
708 |
"target": "production",
|
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;'>
|
@@ -721,11 +723,11 @@ def deploy_to_vercel(code: str):
|
|
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>
|
@@ -766,13 +768,13 @@ def deploy_to_vercel(code: str):
|
|
766 |
"""
|
767 |
|
768 |
|
769 |
-
|
770 |
-
#
|
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>
|
@@ -795,30 +797,251 @@ def handle_deploy(code, deploy_status):
|
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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, {
|
@@ -858,6 +1081,8 @@ def handle_deploy(code, deploy_status):
|
|
858 |
"url": ""
|
859 |
}
|
860 |
|
|
|
|
|
861 |
# ------------------------
|
862 |
# 8) Gradio / Modelscope UI 빌드
|
863 |
# ------------------------
|
@@ -1124,7 +1349,11 @@ with gr.Blocks(css_paths=["app.css"], theme=theme) as demo:
|
|
1124 |
)
|
1125 |
gr.HTML('<div class="help-text">💡 원하는 게임의 설명을 입력하세요. 예: "테트리스 게임 제작해줘."</div>')
|
1126 |
|
1127 |
-
|
|
|
|
|
|
|
|
|
1128 |
deploy_result_container = gr.HTML(
|
1129 |
"""
|
1130 |
<div class="deploy-section">
|
@@ -1133,10 +1362,10 @@ with gr.Blocks(css_paths=["app.css"], theme=theme) as demo:
|
|
1133 |
<div class="no-deploy">아직 배포된 게임이 없습니다.</div>
|
1134 |
</div>
|
1135 |
</div>
|
1136 |
-
"""
|
|
|
1137 |
)
|
1138 |
-
|
1139 |
-
js_trigger = gr.HTML(elem_id="js-trigger", visible=False)
|
1140 |
|
1141 |
# 이벤트 / 콜백
|
1142 |
# Code Drawer
|
@@ -1206,13 +1435,19 @@ with gr.Blocks(css_paths=["app.css"], theme=theme) as demo:
|
|
1206 |
outputs=[sandbox, state_tab]
|
1207 |
)
|
1208 |
|
1209 |
-
|
|
|
|
|
|
|
|
|
1210 |
deploy_btn.click(
|
1211 |
fn=handle_deploy,
|
1212 |
-
inputs=[code_output, deploy_status],
|
1213 |
outputs=[deploy_result_container, deploy_status]
|
1214 |
)
|
1215 |
|
|
|
|
|
1216 |
# ------------------------
|
1217 |
# 9) 실행
|
1218 |
# ------------------------
|
|
|
650 |
# ------------------------
|
651 |
# 7) 실제 배포 함수를 수정하여 화면 표시
|
652 |
# ------------------------
|
653 |
+
###############################################
|
654 |
+
# 1) deploy_to_vercel 함수 (로깅 및 HTML 반환)
|
655 |
+
###############################################
|
656 |
def deploy_to_vercel(code: str):
|
657 |
print("[DEBUG] deploy_to_vercel() 시작. code 길이:", len(code) if code else 0)
|
|
|
658 |
try:
|
659 |
if not code or len(code.strip()) < 10:
|
660 |
print("[DEBUG] code가 짧아서 배포할 수 없음.")
|
|
|
664 |
</div>
|
665 |
<script>console.log('[DEBUG] 배포 실패: code가 너무 짧습니다.');</script>
|
666 |
"""
|
667 |
+
|
668 |
token = "A8IFZmgW2cqA4yUNlLPnci0N"
|
669 |
if not token:
|
670 |
print("[DEBUG] Vercel 토큰이 없음.")
|
|
|
674 |
</div>
|
675 |
<script>console.log('[DEBUG] 배포 실패: Vercel 토큰 없음');</script>
|
676 |
"""
|
677 |
+
|
678 |
project_name = ''.join(random.choice(string.ascii_lowercase) for i in range(6))
|
679 |
deploy_url = "https://api.vercel.com/v13/deployments"
|
680 |
print(f"[DEBUG] 생성된 project_name: {project_name}")
|
|
|
710 |
"target": "production",
|
711 |
"projectSettings": project_settings
|
712 |
}
|
713 |
+
|
714 |
print("[DEBUG] Vercel API 요청 전송중...")
|
715 |
deploy_response = requests.post(deploy_url, headers=headers, json=deploy_data)
|
716 |
print("[DEBUG] 응답 status_code:", deploy_response.status_code)
|
717 |
print("[DEBUG] 응답 body:", deploy_response.text[:300], "..." if len(deploy_response.text) > 300 else "")
|
718 |
+
|
719 |
if deploy_response.status_code != 200:
|
720 |
return f"""
|
721 |
<div style='color:red; padding:10px; border:1px solid red; border-radius:5px;'>
|
|
|
723 |
</div>
|
724 |
<script>console.log('[DEBUG] 배포 실패: {html.escape(deploy_response.text)}');</script>
|
725 |
"""
|
726 |
+
|
727 |
deployment_url = f"https://{project_name}.vercel.app"
|
728 |
print("[DEBUG] 배포 성공 추정. 3초 대기 후 최종 안내...")
|
729 |
time.sleep(3)
|
730 |
+
|
731 |
success_html = f"""
|
732 |
<div style='padding: 15px; background-color: #f0fff4; border: 1px solid #34c759; border-radius: 8px;'>
|
733 |
<h3 style='margin-top: 0; color: #34c759;'>✅ 배포 완료!</h3>
|
|
|
768 |
"""
|
769 |
|
770 |
|
771 |
+
###############################################
|
772 |
+
# 2) handle_deploy 함수 (로깅 + 반환 HTML)
|
773 |
+
###############################################
|
774 |
def handle_deploy(code, deploy_status):
|
775 |
print("[DEBUG] handle_deploy() 함수가 호출되었습니다.")
|
776 |
+
print("[DEBUG] 전달된 code:", repr(code[:300] if code else code))
|
777 |
+
|
778 |
if not code:
|
779 |
js_code = """
|
780 |
<script>
|
|
|
797 |
}
|
798 |
|
799 |
try:
|
|
|
|
|
800 |
print("[DEBUG] 배포 로딩 상태 HTML 생성 중...")
|
|
|
801 |
clean_code = remove_code_block(code)
|
802 |
print("[DEBUG] remove_code_block 후 clean_code 길이:", len(clean_code))
|
803 |
+
|
|
|
804 |
print("[DEBUG] deploy_to_vercel() 호출 시작")
|
805 |
result_html = deploy_to_vercel(clean_code)
|
806 |
print("[DEBUG] deploy_to_vercel() 결과 수신:")
|
807 |
print(result_html[:500], "..." if len(result_html) > 500 else "")
|
808 |
+
|
809 |
+
debug_injection = """
|
810 |
+
<script>
|
811 |
+
console.log('[DEBUG] 배포 후 결과 HTML:', %s);
|
812 |
+
</script>
|
813 |
+
""" % (json.dumps(result_html[:300]) if len(result_html) > 300 else json.dumps(result_html))
|
814 |
+
|
815 |
+
final_html = result_html + debug_injection
|
816 |
|
817 |
+
if "✅ 배포 완료!" in result_html:
|
818 |
+
print("[DEBUG] 배포 성공으로 판단")
|
819 |
+
return final_html, {
|
820 |
+
"is_deployed": True,
|
821 |
+
"status": "success",
|
822 |
+
"url": "",
|
823 |
+
"message": "배포 성공"
|
824 |
+
}
|
825 |
+
else:
|
826 |
+
print("[DEBUG] 배포 실패 또는 오류")
|
827 |
+
return final_html, {
|
828 |
+
"is_deployed": False,
|
829 |
+
"status": "error",
|
830 |
+
"url": "",
|
831 |
+
"message": "배포 실패"
|
832 |
+
}
|
833 |
+
|
834 |
+
except Exception as e:
|
835 |
+
error_msg = str(e)
|
836 |
+
print("[ERROR] handle_deploy에서 예외 발생:", error_msg)
|
837 |
+
exception_js = f"""
|
838 |
+
<script>
|
839 |
+
console.log('[DEBUG] handle_deploy 예외: {error_msg}');
|
840 |
+
showDeployBanner('error', '⚠️ 시스템 오류', '{error_msg}');
|
841 |
+
document.getElementById('deploy-result-box').innerHTML = `
|
842 |
+
<div class="deploy-error">
|
843 |
+
<div class="error-icon">⚠️</div>
|
844 |
+
<div class="error-message">시스템 오류: {error_msg}</div>
|
845 |
+
</div>
|
846 |
+
`;
|
847 |
+
</script>
|
848 |
+
"""
|
849 |
+
return exception_js, {
|
850 |
+
"is_deployed": False,
|
851 |
+
"status": "error",
|
852 |
+
"message": error_msg,
|
853 |
+
"url": ""
|
854 |
+
}
|
855 |
+
|
856 |
+
|
857 |
+
#################################################
|
858 |
+
# 3) deploy_result = gr.HTML(unsafe_allow_html=True)
|
859 |
+
#################################################
|
860 |
+
deploy_result_container = gr.HTML(
|
861 |
+
"""
|
862 |
+
<div class="deploy-section">
|
863 |
+
<div class="deploy-header">📤 배포 결과</div>
|
864 |
+
<div id="deploy-result-box" class="deploy-result-box">
|
865 |
+
<div class="no-deploy">아직 배포된 게임이 없습니다.</div>
|
866 |
+
</div>
|
867 |
+
</div>
|
868 |
+
""",
|
869 |
+
unsafe_allow_html=True # <--- 핵심: 스크립트 실행 허용
|
870 |
+
)
|
871 |
+
|
872 |
+
|
873 |
+
#################################################
|
874 |
+
# 4) deploy_btn 클릭 이벤트
|
875 |
+
#################################################
|
876 |
+
deploy_btn.click(
|
877 |
+
fn=handle_deploy,
|
878 |
+
inputs=[code_output, deploy_status],
|
879 |
+
outputs=[deploy_result_container, deploy_status]
|
880 |
+
)
|
881 |
+
###############################################
|
882 |
+
# 1) deploy_to_vercel 함수 (로깅 및 HTML 반환)
|
883 |
+
###############################################
|
884 |
+
def deploy_to_vercel(code: str):
|
885 |
+
print("[DEBUG] deploy_to_vercel() 시작. code 길이:", len(code) if code else 0)
|
886 |
+
try:
|
887 |
+
if not code or len(code.strip()) < 10:
|
888 |
+
print("[DEBUG] code가 짧아서 배포할 수 없음.")
|
889 |
+
return """
|
890 |
+
<div style='color:red; padding:10px; border:1px solid red; border-radius:5px;'>
|
891 |
+
배포할 코드가 없습니다. 먼저 게임 코드를 생성해주세요.
|
892 |
+
</div>
|
893 |
+
<script>console.log('[DEBUG] 배포 실패: code가 너무 짧습니다.');</script>
|
894 |
+
"""
|
895 |
+
|
896 |
+
token = "A8IFZmgW2cqA4yUNlLPnci0N"
|
897 |
+
if not token:
|
898 |
+
print("[DEBUG] Vercel 토큰이 없음.")
|
899 |
+
return """
|
900 |
+
<div style='color:red; padding:10px; border:1px solid red; border-radius:5px;'>
|
901 |
+
Vercel 토큰이 설정되지 않았습니다.
|
902 |
+
</div>
|
903 |
+
<script>console.log('[DEBUG] 배포 실패: Vercel 토큰 없음');</script>
|
904 |
+
"""
|
905 |
+
|
906 |
+
project_name = ''.join(random.choice(string.ascii_lowercase) for i in range(6))
|
907 |
+
deploy_url = "https://api.vercel.com/v13/deployments"
|
908 |
+
print(f"[DEBUG] 생성된 project_name: {project_name}")
|
909 |
+
|
910 |
+
headers = {
|
911 |
+
"Authorization": f"Bearer {token}",
|
912 |
+
"Content-Type": "application/json"
|
913 |
+
}
|
914 |
+
package_json = {
|
915 |
+
"name": project_name,
|
916 |
+
"version": "1.0.0",
|
917 |
+
"private": True,
|
918 |
+
"dependencies": {"vite": "^5.0.0"},
|
919 |
+
"scripts": {
|
920 |
+
"dev": "vite",
|
921 |
+
"build": "echo 'No build needed' && mkdir -p dist && cp index.html dist/",
|
922 |
+
"preview": "vite preview"
|
923 |
+
}
|
924 |
+
}
|
925 |
+
files = [
|
926 |
+
{"file": "index.html", "data": code},
|
927 |
+
{"file": "package.json", "data": json.dumps(package_json, indent=2)}
|
928 |
+
]
|
929 |
+
project_settings = {
|
930 |
+
"buildCommand": "npm run build",
|
931 |
+
"outputDirectory": "dist",
|
932 |
+
"installCommand": "npm install",
|
933 |
+
"framework": None
|
934 |
+
}
|
935 |
+
deploy_data = {
|
936 |
+
"name": project_name,
|
937 |
+
"files": files,
|
938 |
+
"target": "production",
|
939 |
+
"projectSettings": project_settings
|
940 |
+
}
|
941 |
+
|
942 |
+
print("[DEBUG] Vercel API 요청 전송중...")
|
943 |
+
deploy_response = requests.post(deploy_url, headers=headers, json=deploy_data)
|
944 |
+
print("[DEBUG] 응답 status_code:", deploy_response.status_code)
|
945 |
+
print("[DEBUG] 응답 body:", deploy_response.text[:300], "..." if len(deploy_response.text) > 300 else "")
|
946 |
+
|
947 |
+
if deploy_response.status_code != 200:
|
948 |
+
return f"""
|
949 |
+
<div style='color:red; padding:10px; border:1px solid red; border-radius:5px;'>
|
950 |
+
배포 실패: {html.escape(deploy_response.text)}
|
951 |
+
</div>
|
952 |
+
<script>console.log('[DEBUG] 배포 실패: {html.escape(deploy_response.text)}');</script>
|
953 |
+
"""
|
954 |
+
|
955 |
+
deployment_url = f"https://{project_name}.vercel.app"
|
956 |
+
print("[DEBUG] 배포 성공 추정. 3초 대기 후 최종 안내...")
|
957 |
+
time.sleep(3)
|
958 |
+
|
959 |
+
success_html = f"""
|
960 |
+
<div style='padding: 15px; background-color: #f0fff4; border: 1px solid #34c759; border-radius: 8px;'>
|
961 |
+
<h3 style='margin-top: 0; color: #34c759;'>✅ 배포 완료!</h3>
|
962 |
+
<p>게임이 성공적으로 배포되었습니다.</p>
|
963 |
+
<div style='margin-top: 10px; padding: 10px; background: #f8fafc; border-radius: 6px; display: flex; justify-content: space-between; align-items: center;'>
|
964 |
+
<a href="{deployment_url}" target="_blank" style='color: #0066cc; text-decoration: none; word-break: break-all;'>{deployment_url}</a>
|
965 |
+
<button onclick="navigator.clipboard.writeText('{deployment_url}')" style='background: #0066cc; color: white; border: none; border-radius: 4px; padding: 5px 10px; cursor: pointer;'>복사</button>
|
966 |
+
</div>
|
967 |
+
</div>
|
968 |
+
<script>
|
969 |
+
console.log('[DEBUG] 배포 성공, deployment_url: {deployment_url}');
|
970 |
+
showDeployBanner('success','✅ 배포 완료!','게임이 성공적으로 배포되었습니다.','{deployment_url}');
|
971 |
+
document.getElementById('deploy-result-box').innerHTML = `
|
972 |
+
<div class="deploy-success">
|
973 |
+
<div class="success-icon">✅</div>
|
974 |
+
<div class="success-message">배포 완료!</div>
|
975 |
+
<div class="url-box">
|
976 |
+
<a href="{deployment_url}" target="_blank">{deployment_url}</a>
|
977 |
+
<button class="copy-btn" onclick="navigator.clipboard.writeText('{deployment_url}')">복사</button>
|
978 |
+
</div>
|
979 |
+
</div>
|
980 |
+
`;
|
981 |
+
</script>
|
982 |
+
"""
|
983 |
+
print("[DEBUG] 최종 리턴 HTML 생성 완료")
|
984 |
+
return success_html
|
985 |
+
|
986 |
+
except Exception as e:
|
987 |
+
print("[ERROR] deploy_to_vercel() 예외:", e)
|
988 |
+
return f"""
|
989 |
+
<div style='color:red; padding:10px; border:1px solid red; border-radius:5px;'>
|
990 |
+
오류 발생: {html.escape(str(e))}
|
991 |
+
</div>
|
992 |
+
<script>
|
993 |
+
console.log('[DEBUG] deploy_to_vercel 내부 예외: {html.escape(str(e))}');
|
994 |
+
showDeployBanner('error','⚠️ 시스템 오류','{html.escape(str(e))}');
|
995 |
+
</script>
|
996 |
+
"""
|
997 |
+
|
998 |
+
|
999 |
+
###############################################
|
1000 |
+
# 2) handle_deploy 함수 (로깅 + 반환 HTML)
|
1001 |
+
###############################################
|
1002 |
+
def handle_deploy(code, deploy_status):
|
1003 |
+
print("[DEBUG] handle_deploy() 함수가 호출되었습니다.")
|
1004 |
+
print("[DEBUG] 전달된 code:", repr(code[:300] if code else code))
|
1005 |
+
|
1006 |
+
if not code:
|
1007 |
+
js_code = """
|
1008 |
+
<script>
|
1009 |
+
console.log('[DEBUG] 배포할 코드가 없어 에러 처리');
|
1010 |
+
showDeployBanner('error', '⚠️ 배포 실패', '배포할 코드가 없습니다. 먼저 게임 코드를 생성해주세요.');
|
1011 |
+
document.getElementById('deploy-result-box').innerHTML = `
|
1012 |
+
<div class="deploy-error">
|
1013 |
+
<div class="error-icon">⚠️</div>
|
1014 |
+
<div class="error-message">배포할 코드가 없습니다.</div>
|
1015 |
+
</div>
|
1016 |
+
`;
|
1017 |
+
</script>
|
1018 |
+
"""
|
1019 |
+
print("[DEBUG] code가 없으므로 에러 HTML 반환")
|
1020 |
+
return js_code, {
|
1021 |
+
"is_deployed": False,
|
1022 |
+
"status": "error",
|
1023 |
+
"message": "배포할 코드가 없습니다.",
|
1024 |
+
"url": ""
|
1025 |
+
}
|
1026 |
+
|
1027 |
+
try:
|
1028 |
+
print("[DEBUG] 배포 로딩 상태 HTML 생성 중...")
|
1029 |
+
clean_code = remove_code_block(code)
|
1030 |
+
print("[DEBUG] remove_code_block 후 clean_code 길이:", len(clean_code))
|
1031 |
+
|
1032 |
+
print("[DEBUG] deploy_to_vercel() 호출 시작")
|
1033 |
+
result_html = deploy_to_vercel(clean_code)
|
1034 |
+
print("[DEBUG] deploy_to_vercel() 결과 수신:")
|
1035 |
+
print(result_html[:500], "..." if len(result_html) > 500 else "")
|
1036 |
+
|
1037 |
debug_injection = """
|
1038 |
<script>
|
1039 |
console.log('[DEBUG] 배포 후 결과 HTML:', %s);
|
1040 |
</script>
|
1041 |
""" % (json.dumps(result_html[:300]) if len(result_html) > 300 else json.dumps(result_html))
|
1042 |
|
|
|
1043 |
final_html = result_html + debug_injection
|
1044 |
|
|
|
1045 |
if "✅ 배포 완료!" in result_html:
|
1046 |
print("[DEBUG] 배포 성공으로 판단")
|
1047 |
return final_html, {
|
|
|
1081 |
"url": ""
|
1082 |
}
|
1083 |
|
1084 |
+
|
1085 |
+
|
1086 |
# ------------------------
|
1087 |
# 8) Gradio / Modelscope UI 빌드
|
1088 |
# ------------------------
|
|
|
1349 |
)
|
1350 |
gr.HTML('<div class="help-text">💡 원하는 게임의 설명을 입력하세요. 예: "테트리스 게임 제작해줘."</div>')
|
1351 |
|
1352 |
+
|
1353 |
+
|
1354 |
+
#################################################
|
1355 |
+
# 3) deploy_result = gr.HTML(unsafe_allow_html=True)
|
1356 |
+
#################################################
|
1357 |
deploy_result_container = gr.HTML(
|
1358 |
"""
|
1359 |
<div class="deploy-section">
|
|
|
1362 |
<div class="no-deploy">아직 배포된 게임이 없습니다.</div>
|
1363 |
</div>
|
1364 |
</div>
|
1365 |
+
""",
|
1366 |
+
unsafe_allow_html=True # <--- 핵심: 스크립트 실행 허용
|
1367 |
)
|
1368 |
+
|
|
|
1369 |
|
1370 |
# 이벤트 / 콜백
|
1371 |
# Code Drawer
|
|
|
1435 |
outputs=[sandbox, state_tab]
|
1436 |
)
|
1437 |
|
1438 |
+
|
1439 |
+
|
1440 |
+
#################################################
|
1441 |
+
# 4) deploy_btn 클릭 이벤트
|
1442 |
+
#################################################
|
1443 |
deploy_btn.click(
|
1444 |
fn=handle_deploy,
|
1445 |
+
inputs=[code_output, deploy_status],
|
1446 |
outputs=[deploy_result_container, deploy_status]
|
1447 |
)
|
1448 |
|
1449 |
+
|
1450 |
+
|
1451 |
# ------------------------
|
1452 |
# 9) 실행
|
1453 |
# ------------------------
|