Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,58 +21,40 @@ def create_client():
|
|
| 21 |
|
| 22 |
def process_video(video_file, question, password, progress=gr.Progress()):
|
| 23 |
"""Process video by calling the private space API"""
|
| 24 |
-
if video_file is None:
|
| 25 |
-
raise gr.Error("Please upload a video file")
|
| 26 |
-
|
| 27 |
-
if not question.strip():
|
| 28 |
-
raise gr.Error("Please enter a question")
|
| 29 |
-
|
| 30 |
-
if not password.strip():
|
| 31 |
-
raise gr.Error("Please enter the password")
|
| 32 |
-
|
| 33 |
try:
|
|
|
|
|
|
|
|
|
|
| 34 |
progress(0.2, desc="Connecting to video analysis service...")
|
| 35 |
client = create_client()
|
| 36 |
|
| 37 |
progress(0.4, desc="Uploading and processing video...")
|
| 38 |
-
|
| 39 |
-
# Add timeout for the API call
|
| 40 |
try:
|
| 41 |
result = client.predict(
|
| 42 |
video_file.name, # video_file path
|
| 43 |
question, # question
|
| 44 |
password, # password
|
| 45 |
-
api_name="/process_video"
|
| 46 |
-
timeout=300 # 5 minute timeout
|
| 47 |
)
|
| 48 |
-
except Exception as
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
elif "Video must be shorter" in error_msg:
|
| 53 |
raise gr.Error("Video must be shorter than 2.5 minutes.")
|
| 54 |
-
elif "show_error=True" in error_msg:
|
| 55 |
-
raise gr.Error("Service temporarily unavailable. Please try again in a few minutes.")
|
| 56 |
else:
|
| 57 |
-
|
| 58 |
-
raise gr.Error("Error processing video. Please try again or contact support.")
|
| 59 |
|
| 60 |
-
#
|
| 61 |
if isinstance(result, tuple) and len(result) == 2:
|
| 62 |
analysis_text, video_clip = result
|
| 63 |
-
if not analysis_text or analysis_text.startswith("Error:"):
|
| 64 |
-
raise gr.Error(analysis_text or "Failed to analyze video")
|
| 65 |
return analysis_text, video_clip
|
| 66 |
else:
|
| 67 |
-
|
| 68 |
|
| 69 |
-
except gr.Error:
|
| 70 |
-
raise # Re-raise
|
| 71 |
except Exception as e:
|
| 72 |
-
|
| 73 |
-
raise gr.Error("An unexpected error occurred. Please try again later.")
|
| 74 |
-
|
| 75 |
-
|
| 76 |
|
| 77 |
|
| 78 |
def create_interface():
|
|
|
|
| 21 |
|
| 22 |
def process_video(video_file, question, password, progress=gr.Progress()):
|
| 23 |
"""Process video by calling the private space API"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
try:
|
| 25 |
+
if video_file is None:
|
| 26 |
+
raise gr.Error("No video file uploaded.")
|
| 27 |
+
|
| 28 |
progress(0.2, desc="Connecting to video analysis service...")
|
| 29 |
client = create_client()
|
| 30 |
|
| 31 |
progress(0.4, desc="Uploading and processing video...")
|
|
|
|
|
|
|
| 32 |
try:
|
| 33 |
result = client.predict(
|
| 34 |
video_file.name, # video_file path
|
| 35 |
question, # question
|
| 36 |
password, # password
|
| 37 |
+
api_name="/process_video"
|
|
|
|
| 38 |
)
|
| 39 |
+
except Exception as e:
|
| 40 |
+
if "Invalid password" in str(e):
|
| 41 |
+
raise gr.Error("Invalid password provided.")
|
| 42 |
+
elif "Video must be shorter" in str(e):
|
|
|
|
| 43 |
raise gr.Error("Video must be shorter than 2.5 minutes.")
|
|
|
|
|
|
|
| 44 |
else:
|
| 45 |
+
raise gr.Error(f"Error from video service: {str(e)}")
|
|
|
|
| 46 |
|
| 47 |
+
# Unpack results
|
| 48 |
if isinstance(result, tuple) and len(result) == 2:
|
| 49 |
analysis_text, video_clip = result
|
|
|
|
|
|
|
| 50 |
return analysis_text, video_clip
|
| 51 |
else:
|
| 52 |
+
return str(result), None
|
| 53 |
|
| 54 |
+
except gr.Error as e:
|
| 55 |
+
raise e # Re-raise gr.Error directly
|
| 56 |
except Exception as e:
|
| 57 |
+
raise gr.Error(f"Error processing video: {str(e)}")
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
|
| 60 |
def create_interface():
|