arxivgpt kim commited on
Commit
f139cc1
Β·
verified Β·
1 Parent(s): 61be709

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -32
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
- status_url = f"{api_url}/{job_id}"
37
-
38
- # μž‘μ—… IDλ₯Ό λ°˜ν™˜
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
- gr.Textbox(label="λΉ„λ””μ˜€ 파일의 Google Drive ID"),
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