Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,7 @@ import openai
|
|
7 |
import gradio as gr
|
8 |
from dotenv import load_dotenv
|
9 |
import pinecone
|
|
|
10 |
|
11 |
"""
|
12 |
login to gcp
|
@@ -68,10 +69,13 @@ def text2speech(text):
|
|
68 |
define voice -> gpt -> text -> voice workflow
|
69 |
"""
|
70 |
def transcribe(audio):
|
71 |
-
|
72 |
-
voice_path =
|
|
|
73 |
chat_text = "\n".join([f"{msg['role']}: {msg['content']}" for msg in messages])
|
74 |
-
|
|
|
|
|
75 |
#global messages
|
76 |
|
77 |
"""
|
@@ -128,12 +132,12 @@ def transcribe(audio):
|
|
128 |
|
129 |
output_text = gr.outputs.Textbox(label="Chat Messages")
|
130 |
|
131 |
-
|
132 |
-
|
133 |
-
gr.
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
).launch()
|
|
|
7 |
import gradio as gr
|
8 |
from dotenv import load_dotenv
|
9 |
import pinecone
|
10 |
+
from chat_utils import get_response, reset_chat_history
|
11 |
|
12 |
"""
|
13 |
login to gcp
|
|
|
69 |
define voice -> gpt -> text -> voice workflow
|
70 |
"""
|
71 |
def transcribe(audio):
|
72 |
+
reset_chat_history()
|
73 |
+
voice_path = get_response(audio)
|
74 |
+
messages = get_response(audio, return_messages=True)
|
75 |
chat_text = "\n".join([f"{msg['role']}: {msg['content']}" for msg in messages])
|
76 |
+
with open(voice_path, 'rb') as f:
|
77 |
+
voice_bytes = f.read()
|
78 |
+
return voice_bytes, chat_text
|
79 |
#global messages
|
80 |
|
81 |
"""
|
|
|
132 |
|
133 |
output_text = gr.outputs.Textbox(label="Chat Messages")
|
134 |
|
135 |
+
audio_input = gr.inputs.Audio(source="microphone", type="filepath", label="Speak here...")
|
136 |
+
chat_output = gr.outputs.Textbox(label="Chat Messages")
|
137 |
+
audio_output = gr.outputs.Audio(type="bytes", label="Synthesized Voice")
|
138 |
+
|
139 |
+
gr.Interface(fn=transcribe,
|
140 |
+
inputs=audio_input,
|
141 |
+
outputs=[audio_output, chat_output],
|
142 |
+
live=True,
|
143 |
+
allow_flagging=False).launch()
|