ASG Models commited on
Commit
c962614
·
verified ·
1 Parent(s): b9b713d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -41
app.py CHANGED
@@ -187,51 +187,21 @@ import tempfile
187
  import soundfile as sf
188
  from gradio_client import Client
189
  def add_message(history, message):
190
-
 
191
  if message["text"] is not None:
192
- # sr,response_audio = genrate_speech(message["text"],'asg2024/vits-ar-sa-huba')
193
- # with tempfile.TemporaryFile() as temp_file:
194
- # filename='temp'+str(temp_file.name)+'.wav'
195
- # sf.write(filename,response_audio, sr,format='WAV')
196
- # user_msg1 = {"text": message["text"],
197
- # "files": [{"file":FileData(path=filename)}]}
198
-
199
-
200
- # txt_ai=get_answer_ai(message["text"] )
201
- # sr,response_audio = genrate_speech(txt_ai,'asg2024/vits-ar-sa-huba')
202
- # with tempfile.TemporaryFile() as temp_file:
203
- # filename='temp'+str(temp_file.name)+'.wav'
204
- # sf.write(filename,response_audio, sr,format='WAV')
205
- # bot_msg1 = {"text": txt_ai,
206
- # "files": [{"file":FileData(path=filename)}]}
207
- client = Client("asg2024/wasm-speeker-sa")
208
- result = client.predict(
209
- text="سلام عليكم",
210
- model_choice="asg2024/vits-ar-sa-huba",
211
- api_name="/process_audio"
212
- )
213
- user_msg1 = {"text": message["text"],
214
- "files": [{"file":FileData(path=result[0])}]}
215
- bot_msg1 = {"text": result[2],
216
- "files": [{"file":FileData(path=result[1])}]}
217
- history.append([user_msg1, bot_msg1])
218
-
219
- # history.append((gr.Audio(response_audio,scale=1,streaming=True),None))
220
  return history
221
 
222
  def bot(history,message):
223
- # if message["text"] is not None:
224
- # txt_ai=get_answer_ai(message["text"] )
225
- # sr,response_audio = genrate_speech(txt_ai,'asg2024/vits-ar-sa-huba')
226
- # with tempfile.NamedTemporaryFile(delete=True) as temp_file:
227
- # filename=temp_file.name+'.wav'
228
- # sf.write(filename,response_audio, sr,format='WAV')
229
- # bot_msg1 = {"text": txt_ai,
230
- # "files": [{"file":FileData(path=filename)}]}
231
- # history[-1][1]=bot_msg1
232
-
233
-
234
-
235
  return history, gr.MultimodalTextbox(value=None, interactive=False)
236
 
237
  fig = random_plot()
 
187
  import soundfile as sf
188
  from gradio_client import Client
189
  def add_message(history, message):
190
+ for x in message["files"]:
191
+ history.append(((x,), None))
192
  if message["text"] is not None:
193
+ history.append((message["text"], None))
194
+ response_audio = genrate_speech(message["text"],'asg2024/vits-ar-sa-huba')
195
+ history.append((gr.Audio(response_audio,scale=1,streaming=True),None))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
196
  return history
197
 
198
  def bot(history,message):
199
+ if message["text"] is not None:
200
+ txt_ai=get_answer_ai(message["text"] )
201
+ history[-1][1]=txt_ai#((None,txt_ai))
202
+ response_audio = genrate_speech(txt_ai,'asg2024/vits-ar-sa-huba')
203
+ history.append((None,gr.Audio(response_audio,scale=1,streaming=True)))
204
+
 
 
 
 
 
 
205
  return history, gr.MultimodalTextbox(value=None, interactive=False)
206
 
207
  fig = random_plot()