Pijush2023 commited on
Commit
71b8b4a
·
verified ·
1 Parent(s): d8c5725

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -22
app.py CHANGED
@@ -340,6 +340,35 @@ chain_neo4j = (
340
 
341
 
342
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
343
  def bot(history, choice, tts_choice, retrieval_mode, model_choice):
344
  if not history:
345
  return history
@@ -352,24 +381,20 @@ def bot(history, choice, tts_choice, retrieval_mode, model_choice):
352
 
353
  with concurrent.futures.ThreadPoolExecutor() as executor:
354
  if tts_choice == "Alpha":
355
- audio_future = executor.submit(generate_audio_elevenlabs, response)
356
  elif tts_choice == "Beta":
357
- audio_future = executor.submit(generate_audio_parler_tts, response)
358
- # elif tts_choice == "Gamma":
359
- # audio_future = executor.submit(generate_audio_mars5, response)
360
 
361
- for character in response:
362
- history[-1][1] += character
363
- time.sleep(0.05)
364
- yield history, None
365
-
366
- audio_path = audio_future.result()
367
- yield history, audio_path
368
 
369
  history.append([response, None])
370
 
371
 
372
 
 
373
  phi_custom_template = """
374
  <|system|>
375
  You are a helpful assistant who provides clear, organized, crisp and conversational responses about an events,concerts,sports and all other activities of Birmingham,Alabama .<|end|>
@@ -934,26 +959,23 @@ def generate_audio_parler_tts(text):
934
  for new_audio in streamer:
935
  if new_audio.shape[0] == 0:
936
  break
937
- # Save or process each audio chunk as it is generated
938
- yield sampling_rate, new_audio
 
 
939
 
940
  audio_segments = []
941
- for (sampling_rate, audio_chunk) in generate(text, description, chunk_size_in_s):
942
- audio_segments.append(audio_chunk)
943
-
944
- temp_audio_path = os.path.join(tempfile.gettempdir(), f"parler_tts_audio_chunk_{len(audio_segments)}.wav")
945
- write_wav(temp_audio_path, sampling_rate, audio_chunk.astype(np.float32))
946
- logging.debug(f"Saved chunk to {temp_audio_path}")
947
-
948
 
949
  # Combine all the audio chunks into one audio file
950
  combined_audio = np.concatenate(audio_segments)
951
  combined_audio_path = os.path.join(tempfile.gettempdir(), "parler_tts_combined_audio_stream.wav")
952
-
953
  write_wav(combined_audio_path, sampling_rate, combined_audio.astype(np.float32))
954
 
955
  logging.debug(f"Combined audio saved to {combined_audio_path}")
956
- return combined_audio_path
957
 
958
 
959
 
 
340
 
341
 
342
 
343
+ # def bot(history, choice, tts_choice, retrieval_mode, model_choice):
344
+ # if not history:
345
+ # return history
346
+
347
+ # # Select the model
348
+ # selected_model = chat_model if model_choice == "GPT-4o" else phi_pipe
349
+
350
+ # response, addresses = generate_answer(history[-1][0], choice, retrieval_mode, selected_model)
351
+ # history[-1][1] = ""
352
+
353
+ # with concurrent.futures.ThreadPoolExecutor() as executor:
354
+ # if tts_choice == "Alpha":
355
+ # audio_future = executor.submit(generate_audio_elevenlabs, response)
356
+ # elif tts_choice == "Beta":
357
+ # audio_future = executor.submit(generate_audio_parler_tts, response)
358
+ # # elif tts_choice == "Gamma":
359
+ # # audio_future = executor.submit(generate_audio_mars5, response)
360
+
361
+ # for character in response:
362
+ # history[-1][1] += character
363
+ # time.sleep(0.05)
364
+ # yield history, None
365
+
366
+ # audio_path = audio_future.result()
367
+ # yield history, audio_path
368
+
369
+ # history.append([response, None])
370
+
371
+
372
  def bot(history, choice, tts_choice, retrieval_mode, model_choice):
373
  if not history:
374
  return history
 
381
 
382
  with concurrent.futures.ThreadPoolExecutor() as executor:
383
  if tts_choice == "Alpha":
384
+ audio_stream = generate_audio_elevenlabs(response)
385
  elif tts_choice == "Beta":
386
+ audio_stream = generate_audio_parler_tts(response)
 
 
387
 
388
+ # Stream audio chunks in real-time
389
+ for audio_chunk_path in audio_stream:
390
+ history[-1][1] += response[:len(history[-1][1]) + 1] # Simulate text being generated
391
+ yield history, audio_chunk_path
 
 
 
392
 
393
  history.append([response, None])
394
 
395
 
396
 
397
+
398
  phi_custom_template = """
399
  <|system|>
400
  You are a helpful assistant who provides clear, organized, crisp and conversational responses about an events,concerts,sports and all other activities of Birmingham,Alabama .<|end|>
 
959
  for new_audio in streamer:
960
  if new_audio.shape[0] == 0:
961
  break
962
+ # Save each audio chunk as it is generated
963
+ temp_audio_path = os.path.join(tempfile.gettempdir(), f"parler_tts_audio_chunk_{len(audio_segments)}.wav")
964
+ write_wav(temp_audio_path, sampling_rate, new_audio.astype(np.float32))
965
+ yield temp_audio_path
966
 
967
  audio_segments = []
968
+ for audio_chunk_path in generate(text, description, chunk_size_in_s):
969
+ audio_segments.append(audio_chunk_path)
970
+ yield audio_chunk_path # Yield each audio chunk path immediately
 
 
 
 
971
 
972
  # Combine all the audio chunks into one audio file
973
  combined_audio = np.concatenate(audio_segments)
974
  combined_audio_path = os.path.join(tempfile.gettempdir(), "parler_tts_combined_audio_stream.wav")
 
975
  write_wav(combined_audio_path, sampling_rate, combined_audio.astype(np.float32))
976
 
977
  logging.debug(f"Combined audio saved to {combined_audio_path}")
978
+
979
 
980
 
981