Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -316,12 +316,15 @@ client = InferenceClient(MODEL_NAME)
|
|
316 |
|
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 |
# Handle video input safely
|
326 |
if video:
|
327 |
try:
|
@@ -330,6 +333,7 @@ def respond(video, text_input, history):
|
|
330 |
return "Error: Invalid video input."
|
331 |
|
332 |
result = transcribe_and_predict_video(video_path)
|
|
|
333 |
|
334 |
system_prompt += f"\n\nDetected Emotions:\n"
|
335 |
system_prompt += f"- Text Emotion: {result['text_emotion']}\n"
|
@@ -354,6 +358,7 @@ def respond(video, text_input, history):
|
|
354 |
|
355 |
# Include system prompt
|
356 |
messages.insert(0, {"role": "system", "content": system_prompt})
|
|
|
357 |
|
358 |
response = ""
|
359 |
|
@@ -361,8 +366,10 @@ def respond(video, text_input, history):
|
|
361 |
for message in client.chat_completion(messages, max_tokens=512, stream=True, temperature=0.7, top_p=0.95):
|
362 |
token = message.choices[0].delta.content if message.choices[0].delta else ""
|
363 |
response += token
|
|
|
364 |
yield response
|
365 |
except Exception as e:
|
|
|
366 |
yield f"Error: {str(e)}"
|
367 |
|
368 |
# Define ChatGPT-style UI
|
|
|
316 |
|
317 |
# if __name__ == "__main__":
|
318 |
# demo.launch()
|
|
|
319 |
def respond(video, text_input, history):
|
320 |
"""Processes user input (video, text, or both) and generates a chatbot response."""
|
321 |
messages = []
|
322 |
system_prompt = "You are a chatbot that can analyze emotions from videos and respond accordingly."
|
323 |
|
324 |
+
print("DEBUG: Function called with video:", video)
|
325 |
+
print("DEBUG: Function called with text_input:", text_input)
|
326 |
+
print("DEBUG: Function called with history:", history)
|
327 |
+
|
328 |
# Handle video input safely
|
329 |
if video:
|
330 |
try:
|
|
|
333 |
return "Error: Invalid video input."
|
334 |
|
335 |
result = transcribe_and_predict_video(video_path)
|
336 |
+
print("DEBUG: Video Analysis Result:", result)
|
337 |
|
338 |
system_prompt += f"\n\nDetected Emotions:\n"
|
339 |
system_prompt += f"- Text Emotion: {result['text_emotion']}\n"
|
|
|
358 |
|
359 |
# Include system prompt
|
360 |
messages.insert(0, {"role": "system", "content": system_prompt})
|
361 |
+
print("DEBUG: Final messages sent to chatbot:", messages)
|
362 |
|
363 |
response = ""
|
364 |
|
|
|
366 |
for message in client.chat_completion(messages, max_tokens=512, stream=True, temperature=0.7, top_p=0.95):
|
367 |
token = message.choices[0].delta.content if message.choices[0].delta else ""
|
368 |
response += token
|
369 |
+
print("DEBUG: Received token:", token) # Log tokens received
|
370 |
yield response
|
371 |
except Exception as e:
|
372 |
+
print("DEBUG: Chatbot Error:", str(e))
|
373 |
yield f"Error: {str(e)}"
|
374 |
|
375 |
# Define ChatGPT-style UI
|