| | import gradio as gr |
| | import requests |
| | import time |
| | import os |
| |
|
| | |
| | API_KEY = os.getenv("API_KEY") |
| |
|
| | |
| | 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) |
| |
|
| | 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_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"] |
| | ] |
| | ) |
| |
|
| | |
| | iface.launch() |
| |
|