seawolf2357 commited on
Commit
284a6d8
Β·
1 Parent(s): 41cdd3d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -13
app.py CHANGED
@@ -107,22 +107,36 @@ def generate_status(content_id):
107
  url = API_HOME + END_STATUS
108
  payload = {"id": content_id}
109
  headers = set_header()
110
- response = requests.request("POST", url, json=payload, headers=headers).json()
111
 
112
- # HTTP μƒνƒœμ½”λ“œ 확인
113
- if response['success'] == True:
114
- print(f"정상: {response}")
115
- if response['data']['status'] == 'queued':
116
- print('아직 컨텐츠 URL이 μƒμ„±λ˜μ§€ μ•Šμ•˜μŠ΅λ‹ˆλ‹€.')
117
- return 'PENDING'
118
- if response['data']['status'] == 'processing':
119
- print('컨텐츠 URL이 아직 생성 쀑 μž…λ‹ˆλ‹€.')
120
- return 'PENDING'
121
- elif response['data']['status'] == 'success':
122
- return response['data']['file']
 
 
 
123
 
 
 
 
 
124
  else:
125
- print(f"request μ‹€νŒ¨")
 
 
 
 
 
 
 
 
126
 
127
 
128
  def download_content(url):
 
107
  url = API_HOME + END_STATUS
108
  payload = {"id": content_id}
109
  headers = set_header()
 
110
 
111
+ while True:
112
+ response = requests.request("POST", url, json=payload, headers=headers).json()
113
+
114
+ if response['success']:
115
+ if response['data']['status'] == 'queued' or response['data']['status'] == 'processing':
116
+ print('컨텐츠 생성 쀑... μž μ‹œ ν›„ λ‹€μ‹œ μ‹œλ„ν•˜μ„Έμš”.')
117
+ time.sleep(10) # 10초 λŒ€κΈ°
118
+ elif response['data']['status'] == 'success':
119
+ print('컨텐츠 생성 μ™„λ£Œ!')
120
+ return response['data']['file']
121
+ else:
122
+ print(f"request μ‹€νŒ¨: {response}")
123
+ break
124
+ return 'FAILED'
125
 
126
+ def gradio_generate_status(content_id):
127
+ download_url = generate_status(content_id)
128
+ if download_url != 'FAILED':
129
+ return f"λ‹€μš΄λ‘œλ“œ 링크: {download_url}"
130
  else:
131
+ return "컨텐츠 생성 μ‹€νŒ¨ λ˜λŠ” IDκ°€ 잘λͺ»λ˜μ—ˆμŠ΅λ‹ˆλ‹€."
132
+
133
+ status_iface = gr.Interface(
134
+ fn=gradio_generate_status, # 컨텐츠 μƒνƒœ 확인 및 λ‹€μš΄λ‘œλ“œ 링크 제곡 ν•¨μˆ˜
135
+ inputs=gr.Textbox(label="컨텐츠 ID"),
136
+ outputs=gr.Textbox(label="λ‹€μš΄λ‘œλ“œ 링크 λ˜λŠ” λ©”μ‹œμ§€")
137
+ )
138
+
139
+ status_iface.launch()
140
 
141
 
142
  def download_content(url):