MoiMoi-01 commited on
Commit
3460fd7
·
verified ·
1 Parent(s): 7837aa3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -10
app.py CHANGED
@@ -1,11 +1,14 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
 
 
 
3
 
4
- """
5
- For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
6
- """
7
- client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
8
 
 
 
9
 
10
  def respond(
11
  message,
@@ -35,14 +38,16 @@ def respond(
35
  top_p=top_p,
36
  ):
37
  token = message.choices[0].delta.content
38
-
39
  response += token
40
- yield response
41
 
 
 
 
 
 
42
 
43
- """
44
- For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
45
- """
46
  demo = gr.ChatInterface(
47
  respond,
48
  additional_inputs=[
@@ -57,8 +62,11 @@ demo = gr.ChatInterface(
57
  label="Top-p (nucleus sampling)",
58
  ),
59
  ],
 
 
 
 
60
  )
61
 
62
-
63
  if __name__ == "__main__":
64
  demo.launch()
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
+ import torch
4
+ from TTS.api import TTS
5
+ import soundfile as sf
6
 
7
+ # Load TTS Model (supports multiple models)
8
+ tts_model = TTS("tts_models/en/ljspeech/tacotron2-DDC").to("cuda" if torch.cuda.is_available() else "cpu")
 
 
9
 
10
+ # Hugging Face LLM client
11
+ client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
12
 
13
  def respond(
14
  message,
 
38
  top_p=top_p,
39
  ):
40
  token = message.choices[0].delta.content
 
41
  response += token
42
+ yield response, None # Yielding text response first
43
 
44
+ # Generate speech from text response
45
+ output_audio_path = "response.wav"
46
+ tts_model.tts_to_file(text=response, file_path=output_audio_path)
47
+
48
+ yield response, output_audio_path # Yielding audio response
49
 
50
+ # Gradio Chat Interface with Audio Output
 
 
51
  demo = gr.ChatInterface(
52
  respond,
53
  additional_inputs=[
 
62
  label="Top-p (nucleus sampling)",
63
  ),
64
  ],
65
+ outputs=[
66
+ gr.Textbox(label="Generated Response"),
67
+ gr.Audio(type="filepath", label="TTS Output"),
68
+ ],
69
  )
70
 
 
71
  if __name__ == "__main__":
72
  demo.launch()