Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -528,16 +528,32 @@ def generate_space_name():
|
|
528 |
letters = string.ascii_lowercase
|
529 |
return ''.join(random.choice(letters) for i in range(6))
|
530 |
|
531 |
-
# 배포
|
532 |
def deploy_to_vercel(code: str):
|
533 |
"""
|
534 |
-
Vercel에 배포하는 함수 -
|
535 |
"""
|
536 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
537 |
token = "A8IFZmgW2cqA4yUNlLPnci0N" # 실제 토큰 필요
|
538 |
if not token:
|
539 |
-
return
|
|
|
|
|
|
|
|
|
|
|
540 |
|
|
|
|
|
|
|
541 |
project_name = ''.join(random.choice(string.ascii_lowercase) for i in range(6))
|
542 |
deploy_url = "https://api.vercel.com/v13/deployments"
|
543 |
headers = {
|
@@ -560,7 +576,7 @@ def deploy_to_vercel(code: str):
|
|
560 |
files = [
|
561 |
{
|
562 |
"file": "index.html",
|
563 |
-
"data":
|
564 |
},
|
565 |
{
|
566 |
"file": "package.json",
|
@@ -579,22 +595,43 @@ def deploy_to_vercel(code: str):
|
|
579 |
"target": "production",
|
580 |
"projectSettings": project_settings
|
581 |
}
|
|
|
|
|
582 |
deploy_response = requests.post(deploy_url, headers=headers, json=deploy_data)
|
583 |
if deploy_response.status_code != 200:
|
584 |
-
return
|
|
|
|
|
|
|
|
|
|
|
585 |
|
586 |
-
deployment_url = f"{project_name}.vercel.app"
|
587 |
time.sleep(5)
|
588 |
|
589 |
-
#
|
590 |
-
return
|
591 |
-
|
592 |
-
"
|
593 |
-
"
|
594 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
595 |
except Exception as e:
|
596 |
-
return
|
597 |
-
|
|
|
|
|
|
|
|
|
598 |
|
599 |
|
600 |
def remove_code_block(text):
|
@@ -1525,12 +1562,12 @@ with gr.Blocks(css_paths=["app.css"], theme=theme) as demo:
|
|
1525 |
}
|
1526 |
|
1527 |
# 배포 버튼 클릭 - JavaScript 트리거 및 상태 업데이트
|
|
|
1528 |
deploy_btn.click(
|
1529 |
-
fn=
|
1530 |
-
inputs=[code_output
|
1531 |
-
outputs=[
|
1532 |
)
|
1533 |
-
|
1534 |
# ------------------------
|
1535 |
# 8) 실제 실행
|
1536 |
# ------------------------
|
|
|
528 |
letters = string.ascii_lowercase
|
529 |
return ''.join(random.choice(letters) for i in range(6))
|
530 |
|
531 |
+
# 배포 함수 단순화
|
532 |
def deploy_to_vercel(code: str):
|
533 |
"""
|
534 |
+
Vercel에 배포하는 함수 - 직접 HTML 결과 반환
|
535 |
"""
|
536 |
try:
|
537 |
+
if not code or code.strip() == '':
|
538 |
+
return """
|
539 |
+
<div style="padding: 15px; background: #ffebee; border-left: 5px solid #f44336; margin-bottom: 15px; border-radius: 4px;">
|
540 |
+
<strong style="color: #d32f2f;">⚠️ 배포 실패</strong>
|
541 |
+
<p style="margin: 5px 0 0 0;">배포할 코드가 없습니다. 먼저 게임 코드를 생성해주세요.</p>
|
542 |
+
</div>
|
543 |
+
"""
|
544 |
+
|
545 |
token = "A8IFZmgW2cqA4yUNlLPnci0N" # 실제 토큰 필요
|
546 |
if not token:
|
547 |
+
return """
|
548 |
+
<div style="padding: 15px; background: #ffebee; border-left: 5px solid #f44336; margin-bottom: 15px; border-radius: 4px;">
|
549 |
+
<strong style="color: #d32f2f;">⚠️ 배포 실패</strong>
|
550 |
+
<p style="margin: 5px 0 0 0;">Vercel 토큰이 설정되지 않았습니다.</p>
|
551 |
+
</div>
|
552 |
+
"""
|
553 |
|
554 |
+
# 코드 전처리
|
555 |
+
clean_code = remove_code_block(code)
|
556 |
+
|
557 |
project_name = ''.join(random.choice(string.ascii_lowercase) for i in range(6))
|
558 |
deploy_url = "https://api.vercel.com/v13/deployments"
|
559 |
headers = {
|
|
|
576 |
files = [
|
577 |
{
|
578 |
"file": "index.html",
|
579 |
+
"data": clean_code
|
580 |
},
|
581 |
{
|
582 |
"file": "package.json",
|
|
|
595 |
"target": "production",
|
596 |
"projectSettings": project_settings
|
597 |
}
|
598 |
+
|
599 |
+
# Vercel API 호출
|
600 |
deploy_response = requests.post(deploy_url, headers=headers, json=deploy_data)
|
601 |
if deploy_response.status_code != 200:
|
602 |
+
return f"""
|
603 |
+
<div style="padding: 15px; background: #ffebee; border-left: 5px solid #f44336; margin-bottom: 15px; border-radius: 4px;">
|
604 |
+
<strong style="color: #d32f2f;">⚠️ 배포 실패</strong>
|
605 |
+
<p style="margin: 5px 0 0 0;">API 오류: {deploy_response.text}</p>
|
606 |
+
</div>
|
607 |
+
"""
|
608 |
|
609 |
+
deployment_url = f"https://{project_name}.vercel.app"
|
610 |
time.sleep(5)
|
611 |
|
612 |
+
# 성공 시 HTML로 결과 직접 반환 (게임 링크 + 복사 버튼)
|
613 |
+
return f"""
|
614 |
+
<div style="padding: 15px; background: #e8f5e9; border-left: 5px solid #4caf50; margin-bottom: 15px; border-radius: 4px;">
|
615 |
+
<strong style="color: #2e7d32;">✅ 배포 완료!</strong>
|
616 |
+
<p style="margin: 5px 0;">게임이 성공적으로 배포되었습니다.</p>
|
617 |
+
<div style="background: #f5f5f5; padding: 10px; border-radius: 4px; margin-top: 10px; display: flex; align-items: center; justify-content: space-between;">
|
618 |
+
<a href="{deployment_url}" target="_blank" style="color: #1976d2; text-decoration: none; word-break: break-all; flex: 1;">
|
619 |
+
{deployment_url}
|
620 |
+
</a>
|
621 |
+
<button onclick="navigator.clipboard.writeText('{deployment_url}').then(() => this.textContent = '복사됨!', setTimeout(() => this.textContent = '복사', 1000))"
|
622 |
+
style="background: #1976d2; color: white; border: none; border-radius: 4px; padding: 5px 10px; margin-left: 10px; cursor: pointer;">
|
623 |
+
복사
|
624 |
+
</button>
|
625 |
+
</div>
|
626 |
+
</div>
|
627 |
+
"""
|
628 |
except Exception as e:
|
629 |
+
return f"""
|
630 |
+
<div style="padding: 15px; background: #ffebee; border-left: 5px solid #f44336; margin-bottom: 15px; border-radius: 4px;">
|
631 |
+
<strong style="color: #d32f2f;">⚠️ 시스템 오류</strong>
|
632 |
+
<p style="margin: 5px 0 0 0;">배포 중 오류 발생: {str(e)}</p>
|
633 |
+
</div>
|
634 |
+
"""
|
635 |
|
636 |
|
637 |
def remove_code_block(text):
|
|
|
1562 |
}
|
1563 |
|
1564 |
# 배포 버튼 클릭 - JavaScript 트리거 및 상태 업데이트
|
1565 |
+
|
1566 |
deploy_btn.click(
|
1567 |
+
fn=lambda code: deploy_to_vercel(code), # 직접 HTML 반환
|
1568 |
+
inputs=[code_output],
|
1569 |
+
outputs=[deploy_result_container] # 결과 컨테이너에 직접 출력
|
1570 |
)
|
|
|
1571 |
# ------------------------
|
1572 |
# 8) 실제 실행
|
1573 |
# ------------------------
|