Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -320,10 +320,13 @@ def analyze_video_cohesive(client, video_path: str, prompt: str, progress=None)
|
|
| 320 |
def process_media(src: str, custom_prompt: str, api_key: str, progress=None) -> str:
|
| 321 |
client = get_client(api_key)
|
| 322 |
prompt = (custom_prompt or "").strip() or "Please provide a detailed visual review."
|
|
|
|
| 323 |
if not src:
|
| 324 |
return "Error: No URL or path provided."
|
|
|
|
| 325 |
if progress is not None:
|
| 326 |
progress(0.01, desc="Starting media processing")
|
|
|
|
| 327 |
try:
|
| 328 |
is_image, is_video = determine_media_type(src, progress=progress)
|
| 329 |
except Exception as e:
|
|
@@ -338,6 +341,7 @@ def process_media(src: str, custom_prompt: str, api_key: str, progress=None) ->
|
|
| 338 |
return f"Error: {e}"
|
| 339 |
except Exception as e:
|
| 340 |
return f"Error fetching image: {e}"
|
|
|
|
| 341 |
if progress is not None:
|
| 342 |
progress(0.2, desc="Analyzing image")
|
| 343 |
try:
|
|
@@ -356,14 +360,18 @@ def process_media(src: str, custom_prompt: str, api_key: str, progress=None) ->
|
|
| 356 |
return f"Error: {e}"
|
| 357 |
except Exception as e:
|
| 358 |
return f"Error fetching video: {e}"
|
|
|
|
| 359 |
tmp_path = save_bytes_to_temp(raw, suffix=ext_from_src(src) or ".mp4")
|
|
|
|
| 360 |
try:
|
| 361 |
if progress is not None:
|
| 362 |
progress(0.2, desc="Analyzing video")
|
| 363 |
return analyze_video_cohesive(client, tmp_path, prompt, progress=progress)
|
| 364 |
finally:
|
| 365 |
-
try:
|
| 366 |
-
|
|
|
|
|
|
|
| 367 |
|
| 368 |
try:
|
| 369 |
if progress is not None:
|
|
|
|
| 320 |
def process_media(src: str, custom_prompt: str, api_key: str, progress=None) -> str:
|
| 321 |
client = get_client(api_key)
|
| 322 |
prompt = (custom_prompt or "").strip() or "Please provide a detailed visual review."
|
| 323 |
+
|
| 324 |
if not src:
|
| 325 |
return "Error: No URL or path provided."
|
| 326 |
+
|
| 327 |
if progress is not None:
|
| 328 |
progress(0.01, desc="Starting media processing")
|
| 329 |
+
|
| 330 |
try:
|
| 331 |
is_image, is_video = determine_media_type(src, progress=progress)
|
| 332 |
except Exception as e:
|
|
|
|
| 341 |
return f"Error: {e}"
|
| 342 |
except Exception as e:
|
| 343 |
return f"Error fetching image: {e}"
|
| 344 |
+
|
| 345 |
if progress is not None:
|
| 346 |
progress(0.2, desc="Analyzing image")
|
| 347 |
try:
|
|
|
|
| 360 |
return f"Error: {e}"
|
| 361 |
except Exception as e:
|
| 362 |
return f"Error fetching video: {e}"
|
| 363 |
+
|
| 364 |
tmp_path = save_bytes_to_temp(raw, suffix=ext_from_src(src) or ".mp4")
|
| 365 |
+
|
| 366 |
try:
|
| 367 |
if progress is not None:
|
| 368 |
progress(0.2, desc="Analyzing video")
|
| 369 |
return analyze_video_cohesive(client, tmp_path, prompt, progress=progress)
|
| 370 |
finally:
|
| 371 |
+
try:
|
| 372 |
+
os.remove(tmp_path)
|
| 373 |
+
except Exception:
|
| 374 |
+
pass
|
| 375 |
|
| 376 |
try:
|
| 377 |
if progress is not None:
|