Garvitj commited on
Commit
8a73e97
·
verified ·
1 Parent(s): 3b6bab2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -12
app.py CHANGED
@@ -317,24 +317,31 @@ client = InferenceClient(MODEL_NAME)
317
  # if __name__ == "__main__":
318
  # demo.launch()
319
 
320
-
321
-
322
  def respond(video, text_input, history):
323
  """Processes user input (video, text, or both) and generates a chatbot response."""
324
  messages = []
325
  system_prompt = "You are a chatbot that can analyze emotions from videos and respond accordingly."
326
 
327
  if video is not None:
328
- video_path = video.name # Get uploaded video path
329
- result = transcribe_and_predict_video(video_path)
 
 
 
 
 
330
 
331
- system_prompt += f"\n\nDetected Emotions:\n"
332
- system_prompt += f"- Text Emotion: {result['text_emotion']}\n"
333
- system_prompt += f"- Audio Emotion: {result['audio_emotion']}\n"
334
- system_prompt += f"- Image Emotion: {result['image_emotion']}\n\n"
335
- system_prompt += f"Extracted Speech: {result['extracted_text']}\n"
336
-
337
- messages.append({"role": "user", "content": result["extracted_text"]}) # Add extracted speech
 
 
 
 
338
 
339
  if text_input:
340
  messages.append({"role": "user", "content": text_input}) # Add text input if provided
@@ -358,7 +365,6 @@ def respond(video, text_input, history):
358
  yield response
359
  except Exception as e:
360
  yield f"Error: {str(e)}"
361
-
362
  # Define ChatGPT-style UI
363
  with gr.Blocks(theme="soft") as demo:
364
  gr.Markdown("<h2 align='center'>📹🎤💬 Multi-Modal Chatbot (Video + Text) </h2>")
 
317
  # if __name__ == "__main__":
318
  # demo.launch()
319
 
 
 
320
  def respond(video, text_input, history):
321
  """Processes user input (video, text, or both) and generates a chatbot response."""
322
  messages = []
323
  system_prompt = "You are a chatbot that can analyze emotions from videos and respond accordingly."
324
 
325
  if video is not None:
326
+ if isinstance(video, str):
327
+ video_path = video # If video is already a string (path), use it directly
328
+ elif hasattr(video, "name"):
329
+ video_path = video.name # If video is a file object, get its name
330
+ else:
331
+ yield "Error: Invalid video format."
332
+ return
333
 
334
+ try:
335
+ result = transcribe_and_predict_video(video_path)
336
+ system_prompt += f"\n\nDetected Emotions:\n"
337
+ system_prompt += f"- Text Emotion: {result['text_emotion']}\n"
338
+ system_prompt += f"- Audio Emotion: {result['audio_emotion']}\n"
339
+ system_prompt += f"- Image Emotion: {result['image_emotion']}\n\n"
340
+ system_prompt += f"Extracted Speech: {result['extracted_text']}\n"
341
+ messages.append({"role": "user", "content": result["extracted_text"]}) # Add extracted speech
342
+ except Exception as e:
343
+ yield f"Error processing video: {str(e)}"
344
+ return
345
 
346
  if text_input:
347
  messages.append({"role": "user", "content": text_input}) # Add text input if provided
 
365
  yield response
366
  except Exception as e:
367
  yield f"Error: {str(e)}"
 
368
  # Define ChatGPT-style UI
369
  with gr.Blocks(theme="soft") as demo:
370
  gr.Markdown("<h2 align='center'>📹🎤💬 Multi-Modal Chatbot (Video + Text) </h2>")