arxivgpt kim commited on
Commit
bcc6031
ยท
verified ยท
1 Parent(s): 2d4f7b0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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]
7
+ return f"https://drive.google.com/uc?export=download&id={file_id}"
8
+
9
+ 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,
17
+ "synergize": True,
18
+ "maxCredits": None,
19
+ "webhookUrl": None,
20
+ "model": "sync-1"
21
+ }
22
+
23
+ headers = {
24
+ "Authorization": f"Bearer {api_key}" # Hugging Face Secrets์„ ํ†ตํ•ด ์•ˆ์ „ํ•˜๊ฒŒ ๊ด€๋ฆฌ
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}" # ์ƒํƒœ ํ™•์ธ URL
32
+
33
+ # ์ƒํƒœ ์ฒดํฌ ๋ฃจํ”„
34
+ while True:
35
+ status_response = requests.get(status_url, headers=headers)
36
+ if status_response.status_code == 200:
37
+ status = status_response.json()["status"]
38
+ if status == "COMPLETED":
39
+ return status_response.json()["url"]
40
+ elif status == "FAILED":
41
+ return "๋น„๋””์˜ค ์ƒ์„ฑ ์‹คํŒจ."
42
+ time.sleep(10) # 10์ดˆ ๋Œ€๊ธฐ
43
+ else:
44
+ return "์ƒํƒœ ํ™•์ธ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ."
45
+ else:
46
+ return "API ํ˜ธ์ถœ ์‹คํŒจ."
47
+
48
+ # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ •์˜
49
+ iface = gr.Interface(
50
+ fn=create_video,
51
+ inputs=[gr.inputs.Textbox(label="๋น„๋””์˜ค ํŒŒ์ผ์˜ ๊ตฌ๊ธ€ ๋“œ๋ผ์ด๋ธŒ ๊ณต์œ  ๋งํฌ"),
52
+ gr.inputs.Textbox(label="์˜ค๋””์˜ค ํŒŒ์ผ์˜ ๊ตฌ๊ธ€ ๋“œ๋ผ์ด๋ธŒ ๊ณต์œ  ๋งํฌ")],
53
+ outputs=gr.outputs.Textbox(label="์ƒ์„ฑ๋œ ๋น„๋””์˜ค ๋‹ค์šด๋กœ๋“œ ๋งํฌ"),
54
+ description="๊ตฌ๊ธ€ ๋“œ๋ผ์ด๋ธŒ ๊ณต์œ ๋œ mp4 ํŒŒ์ผ๊ณผ ์˜ค๋””์˜ค ํŒŒ์ผ์„ ํ•ฉ์„ฑํ•˜์—ฌ ๋น„๋””์˜ค๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค."
55
+ )
56
+
57
+ # Hugging Face Space์— ๋ฐฐํฌํ•˜๊ธฐ ์œ„ํ•ด ์‹คํ–‰
58
+ iface.launch()