File size: 2,929 Bytes
bcc6031
 
 
1d106f7
8062da3
 
4237e03
b32565c
ca2b8ce
b32565c
7677dbe
98447ea
f139cc1
 
 
 
 
 
 
 
98447ea
f139cc1
98447ea
f139cc1
98447ea
b32565c
f139cc1
765bc14
 
 
bcc6031
259b983
b912a73
 
bcc6031
 
 
 
 
 
b912a73
bcc6031
 
f139cc1
bcc6031
7677dbe
61be709
bcc6031
98447ea
adf1016
b32565c
abfd02c
 
 
 
 
 
 
 
adf1016
 
bcc6031
98447ea
bcc6031
 
 
abfd02c
 
 
 
 
 
 
 
 
259b983
 
dd19bd2
bcc6031
 
1d106f7
f548d9a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import gradio as gr
import requests
import time
import os

# ν™˜κ²½ λ³€μˆ˜μ—μ„œ API ν‚€λ₯Ό μ½μ–΄μ˜΅λ‹ˆλ‹€.
API_KEY = os.getenv("API_KEY")

# μ‹€μ œ API μ—”λ“œν¬μΈνŠΈ μ£Όμ†Œ
api_url = os.getenv("api_url")

def check_status_and_get_link(job_id):
    status_url = f"{api_url}/{job_id}"
    headers = {"accept": "application/json", "x-api-key": API_KEY}
    
    while True:
        response = requests.get(status_url, headers=headers)
        if response.status_code == 200:
            status = response.json()["status"]
            if status == "COMPLETED":
                return response.json()["url"], "λΉ„λ””μ˜€κ°€ μ„±κ³΅μ μœΌλ‘œ μƒμ„±λ˜μ—ˆμŠ΅λ‹ˆλ‹€."
            elif status == "FAILED":
                return None, "λΉ„λ””μ˜€ 생성 μ‹€νŒ¨."
        else:
            return None, "μƒνƒœ 확인 쀑 였λ₯˜ λ°œμƒ."
        time.sleep(10)  # 10초 κ°„κ²©μœΌλ‘œ μƒνƒœ 체크

def create_video(video_file_id, audio_file_id):
    video_download_link = f"https://drive.google.com/uc?export=download&id={video_file_id}"
    audio_download_link = f"https://drive.google.com/uc?export=download&id={audio_file_id}"

    # ν™˜κ²½ λ³€μˆ˜μ—μ„œ λͺ¨λΈ 버전을 μ½μ–΄μ˜΅λ‹ˆλ‹€.
    MODEL_VERSION = os.getenv("MODEL_VERSION")  # κΈ°λ³Έκ°’ μ„€μ •

    payload = {
        "audioUrl": audio_download_link,
        "videoUrl": video_download_link,
        "synergize": True,
        "maxCredits": None,
        "webhookUrl": None,
        "model": MODEL_VERSION  # ν™˜κ²½ λ³€μˆ˜λ₯Ό μ‚¬μš©
    }

    headers = {"accept": "application/json", "x-api-key": API_KEY, "Content-Type": "application/json"}

    response = requests.post(api_url, json=payload, headers=headers)
    if response.status_code in [200, 201]:
        job_id = response.json()["id"]
        download_url, message = check_status_and_get_link(job_id)
        if download_url:
            # HTML μ½”λ“œ 생성: λΉ„λ””μ˜€ μž„λ² λ“œ 및 λ‹€μš΄λ‘œλ“œ λ²„νŠΌ
            html_code = f'''
            <video width="640" height="360" controls>
                <source src="{download_url}" type="video/mp4">
            </video>
            <br>
            <button onclick="window.location.href='{download_url}'">λ‹€μš΄λ‘œλ“œ</button>
            '''
            return job_id, html_code, "λΉ„λ””μ˜€κ°€ μ„±κ³΅μ μœΌλ‘œ μƒμ„±λ˜μ—ˆμŠ΅λ‹ˆλ‹€."
        else:
            return job_id, "λΉ„λ””μ˜€ 링크λ₯Ό 뢈러올 수 μ—†μŠ΅λ‹ˆλ‹€.", message
    else:
        return "API 호좜 μ‹€νŒ¨", None, None

iface = gr.Interface(
    fn=create_video,
    inputs=[
        gr.Textbox(label="λΉ„λ””μ˜€ 파일의 Google Drive ID"), 
        gr.Textbox(label="μ˜€λ””μ˜€ 파일의 Google Drive ID")
    ],
    outputs=[
        gr.Textbox(label="μž‘μ—… ID"),
        gr.HTML(label="λΉ„λ””μ˜€"),
        gr.Textbox(label="λ©”μ‹œμ§€")
    ],
    examples=[
        ["1E3yJFPAzmytObUp-8EF9ZbjCulsv_RYr", "1EIMH-Eb5cfS0rKFT72-jdXMMnSS5Dvnh"]
    ]
)

# Gradio μ•± μ‹€ν–‰
iface.launch()