arxivgpt kim commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,10 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
import time
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
def convert_google_drive_link(share_link):
|
| 6 |
file_id = share_link.split('/')[-2]
|
|
@@ -10,7 +14,6 @@ def create_video(video_share_link, audio_share_link):
|
|
| 10 |
video_download_link = convert_google_drive_link(video_share_link)
|
| 11 |
audio_download_link = convert_google_drive_link(audio_share_link)
|
| 12 |
|
| 13 |
-
# API ์์ฒญ ํ์ด๋ก๋ ์ค์
|
| 14 |
payload = {
|
| 15 |
"audioUrl": audio_download_link,
|
| 16 |
"videoUrl": video_download_link,
|
|
@@ -21,16 +24,15 @@ def create_video(video_share_link, audio_share_link):
|
|
| 21 |
}
|
| 22 |
|
| 23 |
headers = {
|
| 24 |
-
"Authorization": f"Bearer {api_key}"
|
| 25 |
}
|
| 26 |
|
| 27 |
# API ํธ์ถ ๋ฐ ์๋ต ์ฒ๋ฆฌ
|
| 28 |
-
response = requests.post(api_url, json=payload, headers=headers)
|
| 29 |
if response.status_code == 200:
|
| 30 |
job_id = response.json()["id"]
|
| 31 |
-
status_url = f"{api_url}/{job_id}"
|
| 32 |
|
| 33 |
-
# ์ํ ์ฒดํฌ ๋ฃจํ
|
| 34 |
while True:
|
| 35 |
status_response = requests.get(status_url, headers=headers)
|
| 36 |
if status_response.status_code == 200:
|
|
@@ -39,22 +41,17 @@ def create_video(video_share_link, audio_share_link):
|
|
| 39 |
return status_response.json()["url"]
|
| 40 |
elif status == "FAILED":
|
| 41 |
return "๋น๋์ค ์์ฑ ์คํจ."
|
| 42 |
-
time.sleep(10)
|
| 43 |
else:
|
| 44 |
return "์ํ ํ์ธ ์ค ์ค๋ฅ ๋ฐ์."
|
| 45 |
else:
|
| 46 |
return "API ํธ์ถ ์คํจ."
|
| 47 |
|
| 48 |
-
# Gradio ์ธํฐํ์ด์ค ์ ์
|
| 49 |
iface = gr.Interface(
|
| 50 |
fn=create_video,
|
| 51 |
-
inputs=[
|
| 52 |
-
gr.Textbox(label="๋น๋์ค ํ์ผ์ ๊ตฌ๊ธ ๋๋ผ์ด๋ธ ๊ณต์ ๋งํฌ"),
|
| 53 |
-
gr.Textbox(label="์ค๋์ค ํ์ผ์ ๊ตฌ๊ธ ๋๋ผ์ด๋ธ ๊ณต์ ๋งํฌ")
|
| 54 |
-
],
|
| 55 |
outputs=gr.Textbox(label="์์ฑ๋ ๋น๋์ค ๋ค์ด๋ก๋ ๋งํฌ"),
|
| 56 |
description="๊ตฌ๊ธ ๋๋ผ์ด๋ธ ๊ณต์ ๋ mp4 ํ์ผ๊ณผ ์ค๋์ค ํ์ผ์ ํฉ์ฑํ์ฌ ๋น๋์ค๋ฅผ ์์ฑํฉ๋๋ค."
|
| 57 |
)
|
| 58 |
|
| 59 |
-
# Hugging Face Space์ ๋ฐฐํฌํ๊ธฐ ์ํด ์คํ
|
| 60 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
import time
|
| 4 |
+
import os # ํ๊ฒฝ ๋ณ์์ ์ ๊ทผํ๊ธฐ ์ํด ์ถ๊ฐ
|
| 5 |
+
|
| 6 |
+
# ํ๊ฒฝ ๋ณ์์์ API ํค๋ฅผ ์ฝ์ด์ต๋๋ค.
|
| 7 |
+
api_key = os.getenv("API_KEY")
|
| 8 |
|
| 9 |
def convert_google_drive_link(share_link):
|
| 10 |
file_id = share_link.split('/')[-2]
|
|
|
|
| 14 |
video_download_link = convert_google_drive_link(video_share_link)
|
| 15 |
audio_download_link = convert_google_drive_link(audio_share_link)
|
| 16 |
|
|
|
|
| 17 |
payload = {
|
| 18 |
"audioUrl": audio_download_link,
|
| 19 |
"videoUrl": video_download_link,
|
|
|
|
| 24 |
}
|
| 25 |
|
| 26 |
headers = {
|
| 27 |
+
"Authorization": f"Bearer {api_key}"
|
| 28 |
}
|
| 29 |
|
| 30 |
# API ํธ์ถ ๋ฐ ์๋ต ์ฒ๋ฆฌ
|
| 31 |
+
response = requests.post(api_url, json=payload, headers=headers) # api_url์ ์ค์ API ์๋ํฌ์ธํธ๋ก ์์ ํด์ผ ํฉ๋๋ค.
|
| 32 |
if response.status_code == 200:
|
| 33 |
job_id = response.json()["id"]
|
| 34 |
+
status_url = f"{api_url}/{job_id}"
|
| 35 |
|
|
|
|
| 36 |
while True:
|
| 37 |
status_response = requests.get(status_url, headers=headers)
|
| 38 |
if status_response.status_code == 200:
|
|
|
|
| 41 |
return status_response.json()["url"]
|
| 42 |
elif status == "FAILED":
|
| 43 |
return "๋น๋์ค ์์ฑ ์คํจ."
|
| 44 |
+
time.sleep(10)
|
| 45 |
else:
|
| 46 |
return "์ํ ํ์ธ ์ค ์ค๋ฅ ๋ฐ์."
|
| 47 |
else:
|
| 48 |
return "API ํธ์ถ ์คํจ."
|
| 49 |
|
|
|
|
| 50 |
iface = gr.Interface(
|
| 51 |
fn=create_video,
|
| 52 |
+
inputs=[gr.Textbox(label="๋น๋์ค ํ์ผ์ ๊ตฌ๊ธ ๋๋ผ์ด๋ธ ๊ณต์ ๋งํฌ"), gr.Textbox(label="์ค๋์ค ํ์ผ์ ๊ตฌ๊ธ ๋๋ผ์ด๋ธ ๊ณต์ ๋งํฌ")],
|
|
|
|
|
|
|
|
|
|
| 53 |
outputs=gr.Textbox(label="์์ฑ๋ ๋น๋์ค ๋ค์ด๋ก๋ ๋งํฌ"),
|
| 54 |
description="๊ตฌ๊ธ ๋๋ผ์ด๋ธ ๊ณต์ ๋ mp4 ํ์ผ๊ณผ ์ค๋์ค ํ์ผ์ ํฉ์ฑํ์ฌ ๋น๋์ค๋ฅผ ์์ฑํฉ๋๋ค."
|
| 55 |
)
|
| 56 |
|
|
|
|
| 57 |
iface.launch()
|