lyimo commited on
Commit
a40ce12
·
1 Parent(s): c827f71

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -21
app.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  import openai
2
  import gradio as gr
3
 
@@ -19,18 +21,11 @@ def generate_response(transcribed_text):
19
  )
20
  return response.choices[0].text
21
 
22
- def run_cmd(command):
23
- try:
24
- print(command)
25
- call(command)
26
- except KeyboardInterrupt:
27
- print("Process interrupted")
28
- sys.exit(1)
29
-
30
  def inference(text):
31
- cmd = ['tts', '--text', text]
32
- run_cmd(cmd)
33
- return 'tts_output.wav'
 
34
 
35
  def process_audio_and_respond(audio):
36
  text = transcribe(audio)
@@ -38,13 +33,16 @@ def process_audio_and_respond(audio):
38
  output_file = inference(response_text)
39
  return output_file
40
 
41
- demo = gr.Blocks()
42
-
43
- with demo:
44
- audio_file = gr.inputs.Audio(source="microphone", type="filepath")
45
- button = gr.Button("Uliza Swali")
46
- outputs = gr.outputs.Audio(type="filepath", label="Output Audio")
47
-
48
- button.click(fn=process_audio_and_respond, inputs=audio_file, outputs=outputs)
49
-
50
- demo.launch()
 
 
 
 
1
+ import os
2
+ import subprocess
3
  import openai
4
  import gradio as gr
5
 
 
21
  )
22
  return response.choices[0].text
23
 
 
 
 
 
 
 
 
 
24
  def inference(text):
25
+ output_file = "tts_output.wav"
26
+ cmd = ['tts', '--text', text, '--out_path', output_file]
27
+ subprocess.run(cmd, check=True)
28
+ return output_file
29
 
30
  def process_audio_and_respond(audio):
31
  text = transcribe(audio)
 
33
  output_file = inference(response_text)
34
  return output_file
35
 
36
+ demo = gr.Interface(
37
+ process_audio_and_respond,
38
+ gr.inputs.Audio(source="microphone", type="filepath", label="Speak your question"),
39
+ gr.outputs.Audio(type="filepath", label="Answer"),
40
+ title="AI Question Answering",
41
+ description="Ask any question and get an AI-generated answer as audio output.",
42
+ theme="compact",
43
+ layout="vertical",
44
+ allow_flagging=False,
45
+ live=True,
46
+ )
47
+
48
+ demo.launch()