arxivgpt kim commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,8 +9,23 @@ API_KEY = os.getenv("API_KEY")
|
|
| 9 |
# μ€μ API μλν¬μΈνΈ μ£Όμ
|
| 10 |
api_url = "https://api.synclabs.so/video"
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
def create_video(video_file_id, audio_file_id):
|
| 13 |
-
# μ¬μ©μλ‘λΆν° μ
λ ₯λ°μ νμΌ IDλ₯Ό κΈ°λ°μΌλ‘ λ€μ΄λ‘λ λ§ν¬ μμ±
|
| 14 |
video_download_link = f"https://drive.google.com/uc?export=download&id={video_file_id}"
|
| 15 |
audio_download_link = f"https://drive.google.com/uc?export=download&id={audio_file_id}"
|
| 16 |
|
|
@@ -23,46 +38,22 @@ def create_video(video_file_id, audio_file_id):
|
|
| 23 |
"model": "sync-1"
|
| 24 |
}
|
| 25 |
|
| 26 |
-
headers = {
|
| 27 |
-
"accept": "application/json",
|
| 28 |
-
"x-api-key": API_KEY,
|
| 29 |
-
"Content-Type": "application/json"
|
| 30 |
-
}
|
| 31 |
|
| 32 |
-
# API νΈμΆ
|
| 33 |
response = requests.post(api_url, json=payload, headers=headers)
|
| 34 |
if response.status_code in [200, 201]:
|
| 35 |
job_id = response.json()["id"]
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
yield f"μμ
ID: {job_id}. μμ± μνλ₯Ό νμΈμ€μ
λλ€..."
|
| 40 |
-
|
| 41 |
-
while True:
|
| 42 |
-
status_response = requests.get(status_url, headers=headers)
|
| 43 |
-
if status_response.status_code == 200:
|
| 44 |
-
status = status_response.json()["status"]
|
| 45 |
-
if status == "COMPLETED":
|
| 46 |
-
download_url = status_response.json()["url"]
|
| 47 |
-
return download_url # μμ±λ λΉλμ€μ λ€μ΄λ‘λ λ§ν¬ λ°ν
|
| 48 |
-
elif status == "FAILED":
|
| 49 |
-
return "λΉλμ€ μμ± μ€ν¨."
|
| 50 |
-
time.sleep(10) # μν νμΈμ μν΄ μ μ λκΈ°
|
| 51 |
-
else:
|
| 52 |
-
return "μν νμΈ μ€ μ€λ₯ λ°μ."
|
| 53 |
else:
|
| 54 |
return "API νΈμΆ μ€ν¨."
|
| 55 |
|
| 56 |
iface = gr.Interface(
|
| 57 |
fn=create_video,
|
| 58 |
-
inputs=[
|
| 59 |
-
|
| 60 |
-
gr.Textbox(label="μ€λμ€ νμΌμ Google Drive ID")
|
| 61 |
-
],
|
| 62 |
-
outputs=[
|
| 63 |
-
gr.Textbox(label="μμ
ID λ° μν"),
|
| 64 |
-
gr.Video(label="μμ±λ λΉλμ€")
|
| 65 |
-
],
|
| 66 |
description="Google Drive 곡μ λ mp4 νμΌκ³Ό μ€λμ€ νμΌμ IDλ₯Ό μ
λ ₯νμ¬ λΉλμ€λ₯Ό μμ±ν©λλ€."
|
| 67 |
)
|
| 68 |
|
|
|
|
| 9 |
# μ€μ API μλν¬μΈνΈ μ£Όμ
|
| 10 |
api_url = "https://api.synclabs.so/video"
|
| 11 |
|
| 12 |
+
def check_status(job_id):
|
| 13 |
+
status_url = f"{api_url}/{job_id}"
|
| 14 |
+
headers = {"accept": "application/json", "x-api-key": API_KEY}
|
| 15 |
+
|
| 16 |
+
while True:
|
| 17 |
+
response = requests.get(status_url, headers=headers)
|
| 18 |
+
if response.status_code == 200:
|
| 19 |
+
status = response.json()["status"]
|
| 20 |
+
if status == "COMPLETED":
|
| 21 |
+
return response.json()["url"]
|
| 22 |
+
elif status == "FAILED":
|
| 23 |
+
return "λΉλμ€ μμ± μ€ν¨."
|
| 24 |
+
else:
|
| 25 |
+
return "μν νμΈ μ€ μ€λ₯ λ°μ."
|
| 26 |
+
time.sleep(10) # 10μ΄ κ°κ²©μΌλ‘ μν 체ν¬
|
| 27 |
+
|
| 28 |
def create_video(video_file_id, audio_file_id):
|
|
|
|
| 29 |
video_download_link = f"https://drive.google.com/uc?export=download&id={video_file_id}"
|
| 30 |
audio_download_link = f"https://drive.google.com/uc?export=download&id={audio_file_id}"
|
| 31 |
|
|
|
|
| 38 |
"model": "sync-1"
|
| 39 |
}
|
| 40 |
|
| 41 |
+
headers = {"accept": "application/json", "x-api-key": API_KEY, "Content-Type": "application/json"}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
+
# API νΈμΆ
|
| 44 |
response = requests.post(api_url, json=payload, headers=headers)
|
| 45 |
if response.status_code in [200, 201]:
|
| 46 |
job_id = response.json()["id"]
|
| 47 |
+
# μν νμΈ λ° μ΅μ’
κ²°κ³Ό λ°ν
|
| 48 |
+
download_url = check_status(job_id)
|
| 49 |
+
return download_url
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
else:
|
| 51 |
return "API νΈμΆ μ€ν¨."
|
| 52 |
|
| 53 |
iface = gr.Interface(
|
| 54 |
fn=create_video,
|
| 55 |
+
inputs=[gr.Textbox(label="λΉλμ€ νμΌμ Google Drive ID"), gr.Textbox(label="μ€λμ€ νμΌμ Google Drive ID")],
|
| 56 |
+
outputs=gr.Textbox(label="μμ±λ λΉλμ€ λ€μ΄λ‘λ λ§ν¬"),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
description="Google Drive 곡μ λ mp4 νμΌκ³Ό μ€λμ€ νμΌμ IDλ₯Ό μ
λ ₯νμ¬ λΉλμ€λ₯Ό μμ±ν©λλ€."
|
| 58 |
)
|
| 59 |
|