Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,7 @@ from PIL import Image
|
|
8 |
import moviepy.editor as mp
|
9 |
from gtts import gTTS
|
10 |
from groq import Groq
|
|
|
11 |
|
12 |
client = Groq(
|
13 |
api_key="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",
|
@@ -19,7 +20,7 @@ audio_pipeline = pipeline("audio-classification", model="audeering/wav2vec2-larg
|
|
19 |
text_pipeline = pipeline("text-classification", model="SamLowe/roberta-base-go_emotions", top_k=2)
|
20 |
|
21 |
conversation_history = []
|
22 |
-
max_history_length = 3
|
23 |
|
24 |
def process_input(video_stream, conversation_history):
|
25 |
if isinstance(video_stream, str):
|
@@ -75,7 +76,7 @@ def process_input(video_stream, conversation_history):
|
|
75 |
audio_emotions = audio_pipeline(audio_data)
|
76 |
if audio_emotions:
|
77 |
audio_emotion = audio_emotions[0]['label']
|
78 |
-
print("Audio emotion:", audio_emotion)
|
79 |
|
80 |
# Recognize audio
|
81 |
text_input = recognizer.recognize_google(audio)
|
@@ -119,12 +120,8 @@ def process_input(video_stream, conversation_history):
|
|
119 |
print(f"Error processing text data: {e}")
|
120 |
|
121 |
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
if conversation_history is not None:
|
127 |
-
conversation_history = conversation_history[-max_history_length:] # Keep most recent entries
|
128 |
conversation_history.append({
|
129 |
"user_input": text_input,
|
130 |
"image_features": image_features,
|
@@ -188,8 +185,10 @@ def display_history(conversation_history):
|
|
188 |
if "user_input" in turn:
|
189 |
history_str += f"User: {turn['user_input']}\n"
|
190 |
if "ai_response" in turn:
|
|
|
|
|
191 |
history_str += f"Therapist: {turn['ai_response']}\n\n"
|
192 |
-
return history_str
|
193 |
|
194 |
|
195 |
# Create the Gradio interface
|
@@ -211,9 +210,6 @@ gr.Interface .gradio-description {
|
|
211 |
font-size: 16px;
|
212 |
margin-top: 10px;
|
213 |
}
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
"""
|
218 |
|
219 |
description = """
|
|
|
8 |
import moviepy.editor as mp
|
9 |
from gtts import gTTS
|
10 |
from groq import Groq
|
11 |
+
import re
|
12 |
|
13 |
client = Groq(
|
14 |
api_key="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",
|
|
|
20 |
text_pipeline = pipeline("text-classification", model="SamLowe/roberta-base-go_emotions", top_k=2)
|
21 |
|
22 |
conversation_history = []
|
23 |
+
# max_history_length = 3
|
24 |
|
25 |
def process_input(video_stream, conversation_history):
|
26 |
if isinstance(video_stream, str):
|
|
|
76 |
audio_emotions = audio_pipeline(audio_data)
|
77 |
if audio_emotions:
|
78 |
audio_emotion = audio_emotions[0]['label']
|
79 |
+
print("Audio emotion:", audio_emotion)a
|
80 |
|
81 |
# Recognize audio
|
82 |
text_input = recognizer.recognize_google(audio)
|
|
|
120 |
print(f"Error processing text data: {e}")
|
121 |
|
122 |
|
|
|
|
|
|
|
|
|
123 |
if conversation_history is not None:
|
124 |
+
# conversation_history = conversation_history[-max_history_length:] # Keep most recent entries
|
125 |
conversation_history.append({
|
126 |
"user_input": text_input,
|
127 |
"image_features": image_features,
|
|
|
185 |
if "user_input" in turn:
|
186 |
history_str += f"User: {turn['user_input']}\n"
|
187 |
if "ai_response" in turn:
|
188 |
+
ai_response = turn['ai_response']
|
189 |
+
ai_response = re.sub(r'\*\*', '', ai_response)
|
190 |
history_str += f"Therapist: {turn['ai_response']}\n\n"
|
191 |
+
return history_str
|
192 |
|
193 |
|
194 |
# Create the Gradio interface
|
|
|
210 |
font-size: 16px;
|
211 |
margin-top: 10px;
|
212 |
}
|
|
|
|
|
|
|
213 |
"""
|
214 |
|
215 |
description = """
|