Spaces:
Runtime error
Runtime error
ASG Models
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -181,23 +181,40 @@ def random_plot():
|
|
| 181 |
|
| 182 |
def print_like_dislike(x: gr.LikeData):
|
| 183 |
print(x.index, x.value, x.liked)
|
| 184 |
-
|
|
|
|
|
|
|
|
|
|
| 185 |
def add_message(history, message):
|
| 186 |
-
|
| 187 |
-
history.append(((x,), None))
|
| 188 |
if message["text"] is not None:
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
return history
|
| 193 |
|
| 194 |
def bot(history,message):
|
| 195 |
if message["text"] is not None:
|
| 196 |
txt_ai=get_answer_ai(message["text"] )
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
return history, gr.MultimodalTextbox(value=None, interactive=False)
|
| 202 |
|
| 203 |
fig = random_plot()
|
|
|
|
| 181 |
|
| 182 |
def print_like_dislike(x: gr.LikeData):
|
| 183 |
print(x.index, x.value, x.liked)
|
| 184 |
+
from gradio_multimodalchatbot import MultimodalChatbot
|
| 185 |
+
from gradio.data_classes import FileData
|
| 186 |
+
import tempfile
|
| 187 |
+
import soundfile as sf
|
| 188 |
def add_message(history, message):
|
| 189 |
+
|
|
|
|
| 190 |
if message["text"] is not None:
|
| 191 |
+
sr,response_audio = genrate_speech(message["text"],'asg2024/vits-ar-sa-huba')
|
| 192 |
+
with tempfile.NamedTemporaryFile(delete=True) as temp_file:
|
| 193 |
+
filename=temp_file.name+'.wav'
|
| 194 |
+
sf.write(filename,response_audio, sr,format='WAV')
|
| 195 |
+
user_msg1 = {"text": message["text"],
|
| 196 |
+
"files": [{"file":FileData(path=filename)}]}
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
history.append([user_msg1, None])
|
| 201 |
+
|
| 202 |
+
# history.append((gr.Audio(response_audio,scale=1,streaming=True),None))
|
| 203 |
return history
|
| 204 |
|
| 205 |
def bot(history,message):
|
| 206 |
if message["text"] is not None:
|
| 207 |
txt_ai=get_answer_ai(message["text"] )
|
| 208 |
+
sr,response_audio = genrate_speech(txt_ai,'asg2024/vits-ar-sa-huba')
|
| 209 |
+
with tempfile.NamedTemporaryFile(delete=True) as temp_file:
|
| 210 |
+
filename=temp_file.name+'.wav'
|
| 211 |
+
sf.write(filename,response_audio, sr,format='WAV')
|
| 212 |
+
bot_msg1 = {"text": txt_ai,
|
| 213 |
+
"files": [{"file":FileData(path=filename)}]}
|
| 214 |
+
history[-1][1]=bot_msg1
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
|
| 218 |
return history, gr.MultimodalTextbox(value=None, interactive=False)
|
| 219 |
|
| 220 |
fig = random_plot()
|