Update app.py
Browse files
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 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
| 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.
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|