Update app.py
Browse files
app.py
CHANGED
@@ -264,75 +264,86 @@ def generate_video(image, prompt):
|
|
264 |
status_data = query_response.json()
|
265 |
status = status_data.get('status')
|
266 |
|
267 |
-
if status == 'Success':
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
file_response = requests.get(
|
276 |
-
retrieve_url,
|
277 |
-
headers={'authorization': f'Bearer {API_KEY}'},
|
278 |
-
params=params
|
279 |
-
)
|
280 |
-
|
281 |
-
if not file_response.ok:
|
282 |
-
return "Failed to retrieve video file"
|
283 |
-
|
284 |
-
try:
|
285 |
-
file_data = file_response.json()
|
286 |
-
download_url = file_data.get('file', {}).get('download_url')
|
287 |
-
if not download_url:
|
288 |
-
return "Failed to get download URL"
|
289 |
-
|
290 |
-
result_info = {
|
291 |
-
"timestamp": datetime.now().strftime("%Y%m%d_%H%M%S"),
|
292 |
-
"input_image": image_url,
|
293 |
-
"output_video_url": download_url,
|
294 |
-
"prompt": prompt
|
295 |
-
}
|
296 |
-
logger.info(f"Video generation result: {json.dumps(result_info, indent=2)}")
|
297 |
-
|
298 |
-
video_response = requests.get(download_url)
|
299 |
-
if not video_response.ok:
|
300 |
-
return "Failed to download video"
|
301 |
-
|
302 |
-
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
303 |
-
output_path = os.path.join(temp_dir, f"output_{timestamp}.mp4")
|
304 |
-
|
305 |
-
with open(output_path, 'wb') as f:
|
306 |
-
f.write(video_response.content)
|
307 |
-
|
308 |
-
final_path = add_watermark(output_path)
|
309 |
-
|
310 |
-
# ์ค๋์ค ์ฒ๋ฆฌ ์ถ๊ฐ
|
311 |
-
try:
|
312 |
-
final_path_with_audio = video_to_audio(
|
313 |
-
final_path,
|
314 |
-
prompt=prompt,
|
315 |
-
negative_prompt="music",
|
316 |
-
seed=-1,
|
317 |
-
num_steps=25,
|
318 |
-
cfg_strength=4.5,
|
319 |
-
duration=8
|
320 |
-
)
|
321 |
-
|
322 |
-
# ์์ ํ์ผ ์ ๋ฆฌ
|
323 |
-
if output_path != final_path:
|
324 |
-
os.remove(output_path)
|
325 |
-
if final_path != final_path_with_audio:
|
326 |
-
os.remove(final_path)
|
327 |
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
332 |
|
333 |
except Exception as e:
|
334 |
-
logger.error(f"Error
|
335 |
-
return "Error
|
336 |
|
337 |
css = """
|
338 |
footer {display: none}
|
|
|
264 |
status_data = query_response.json()
|
265 |
status = status_data.get('status')
|
266 |
|
267 |
+
if status == 'Success':
|
268 |
+
file_id = status_data.get('file_id')
|
269 |
+
if not file_id:
|
270 |
+
return "Failed to get file ID"
|
271 |
|
272 |
+
retrieve_url = "https://api.minimaxi.chat/v1/files/retrieve"
|
273 |
+
params = {'file_id': file_id}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
274 |
|
275 |
+
file_response = requests.get(
|
276 |
+
retrieve_url,
|
277 |
+
headers={'authorization': f'Bearer {API_KEY}'},
|
278 |
+
params=params
|
279 |
+
)
|
280 |
+
|
281 |
+
if not file_response.ok:
|
282 |
+
return "Failed to retrieve video file"
|
283 |
+
|
284 |
+
try:
|
285 |
+
file_data = file_response.json()
|
286 |
+
download_url = file_data.get('file', {}).get('download_url')
|
287 |
+
if not download_url:
|
288 |
+
return "Failed to get download URL"
|
289 |
+
|
290 |
+
result_info = {
|
291 |
+
"timestamp": datetime.now().strftime("%Y%m%d_%H%M%S"),
|
292 |
+
"input_image": image_url,
|
293 |
+
"output_video_url": download_url,
|
294 |
+
"prompt": prompt
|
295 |
+
}
|
296 |
+
logger.info(f"Video generation result: {json.dumps(result_info, indent=2)}")
|
297 |
+
|
298 |
+
video_response = requests.get(download_url)
|
299 |
+
if not video_response.ok:
|
300 |
+
return "Failed to download video"
|
301 |
+
|
302 |
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
303 |
+
output_path = os.path.join(temp_dir, f"output_{timestamp}.mp4")
|
304 |
+
|
305 |
+
with open(output_path, 'wb') as f:
|
306 |
+
f.write(video_response.content)
|
307 |
+
|
308 |
+
final_path = add_watermark(output_path)
|
309 |
+
|
310 |
+
# ์ค๋์ค ์ฒ๋ฆฌ ์ถ๊ฐ
|
311 |
+
try:
|
312 |
+
final_path_with_audio = video_to_audio(
|
313 |
+
final_path,
|
314 |
+
prompt=prompt,
|
315 |
+
negative_prompt="music",
|
316 |
+
seed=-1,
|
317 |
+
num_steps=25,
|
318 |
+
cfg_strength=4.5,
|
319 |
+
duration=8
|
320 |
+
)
|
321 |
+
|
322 |
+
# ์์ ํ์ผ ์ ๋ฆฌ
|
323 |
+
if output_path != final_path:
|
324 |
+
os.remove(output_path)
|
325 |
+
if final_path != final_path_with_audio:
|
326 |
+
os.remove(final_path)
|
327 |
+
|
328 |
+
return final_path_with_audio
|
329 |
+
except Exception as e:
|
330 |
+
logger.error(f"Error in audio processing: {str(e)}")
|
331 |
+
return final_path # ์ค๋์ค ์ฒ๋ฆฌ ์คํจ ์ ์ํฐ๋งํฌ๋ง ๋ ๋น๋์ค ๋ฐํ
|
332 |
+
|
333 |
+
except Exception as e:
|
334 |
+
logger.error(f"Error processing video file: {str(e)}")
|
335 |
+
return "Error processing video file"
|
336 |
+
|
337 |
+
elif status == 'Fail':
|
338 |
+
return "Video generation failed"
|
339 |
+
|
340 |
+
attempt += 1
|
341 |
+
|
342 |
+
return "Timeout waiting for video generation"
|
343 |
|
344 |
except Exception as e:
|
345 |
+
logger.error(f"Error in video generation: {str(e)}")
|
346 |
+
return f"Error in video generation process: {str(e)}"
|
347 |
|
348 |
css = """
|
349 |
footer {display: none}
|