Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,7 @@ from dotenv import load_dotenv
|
|
6 |
from pathlib import Path
|
7 |
from time import sleep
|
8 |
import audioread
|
|
|
9 |
|
10 |
load_dotenv(override=True)
|
11 |
key = os.getenv('OPENAI_API_KEY')
|
@@ -155,9 +156,18 @@ def new_func(user_window):
|
|
155 |
dataFile = dataDir + user_window + '_log.txt'
|
156 |
return dataFile
|
157 |
|
158 |
-
|
159 |
-
|
160 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
|
162 |
def transcribe(user, pwd, fpath):
|
163 |
user = user.lower().strip()
|
@@ -178,6 +188,13 @@ def transcribe(user, pwd, fpath):
|
|
178 |
def pause_message():
|
179 |
return "Audio input is paused. Resume or Stop as desired"
|
180 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
with gr.Blocks() as demo:
|
182 |
history = gr.State([])
|
183 |
password = gr.State("")
|
@@ -200,6 +217,7 @@ with gr.Blocks() as demo:
|
|
200 |
# gpt_chooser=gr.Radio(choices=[("GPT-3.5","gpt-3.5-turbo"),("GPT-4o","gpt-4o-mini")],
|
201 |
# value="gpt-3.5-turbo", label="GPT Model", interactive=True)
|
202 |
submit_window = gr.Button(value="Submit Prompt/Question")
|
|
|
203 |
prompt_window = gr.Textbox(label = "Prompt or Question")
|
204 |
output_window = gr.Textbox(label = "Dialog")
|
205 |
submit_window.click(chat, inputs=[prompt_window, user_window, password, history, output_window, model],
|
@@ -209,4 +227,6 @@ with gr.Blocks() as demo:
|
|
209 |
outputs=[prompt_window])
|
210 |
audio_widget.pause_recording(fn=pause_message, outputs=[prompt_window])
|
211 |
reset_button.add(audio_widget)
|
212 |
-
|
|
|
|
|
|
6 |
from pathlib import Path
|
7 |
from time import sleep
|
8 |
import audioread
|
9 |
+
from playsound3 import playsound
|
10 |
|
11 |
load_dotenv(override=True)
|
12 |
key = os.getenv('OPENAI_API_KEY')
|
|
|
156 |
dataFile = dataDir + user_window + '_log.txt'
|
157 |
return dataFile
|
158 |
|
159 |
+
def play_sound(txt):
|
160 |
+
if len(txt) < 10:
|
161 |
+
gr.Info(message='Dialog must be at least 10 characters long',duration=4)
|
162 |
+
return
|
163 |
+
speech_path = dataDir + 'speech.wav'
|
164 |
+
response = client.audio.speech.create(model='tts-1', voice='fable', input=txt)
|
165 |
+
with open(speech_path, 'wb') as fpath:
|
166 |
+
fpath.write(response.content)
|
167 |
+
playsound(speech_path)
|
168 |
+
if os.path.exists(speech_path):
|
169 |
+
os.remove(speech_path)
|
170 |
+
|
171 |
|
172 |
def transcribe(user, pwd, fpath):
|
173 |
user = user.lower().strip()
|
|
|
188 |
def pause_message():
|
189 |
return "Audio input is paused. Resume or Stop as desired"
|
190 |
|
191 |
+
def set_speak(txt):
|
192 |
+
vis = False;
|
193 |
+
if len(txt) > 10:
|
194 |
+
vis = True
|
195 |
+
return gr.Button(visible=vis)
|
196 |
+
|
197 |
+
|
198 |
with gr.Blocks() as demo:
|
199 |
history = gr.State([])
|
200 |
password = gr.State("")
|
|
|
217 |
# gpt_chooser=gr.Radio(choices=[("GPT-3.5","gpt-3.5-turbo"),("GPT-4o","gpt-4o-mini")],
|
218 |
# value="gpt-3.5-turbo", label="GPT Model", interactive=True)
|
219 |
submit_window = gr.Button(value="Submit Prompt/Question")
|
220 |
+
speak_dialog = gr.Button(value="Speak Dialog",visible=False)
|
221 |
prompt_window = gr.Textbox(label = "Prompt or Question")
|
222 |
output_window = gr.Textbox(label = "Dialog")
|
223 |
submit_window.click(chat, inputs=[prompt_window, user_window, password, history, output_window, model],
|
|
|
227 |
outputs=[prompt_window])
|
228 |
audio_widget.pause_recording(fn=pause_message, outputs=[prompt_window])
|
229 |
reset_button.add(audio_widget)
|
230 |
+
speak_dialog.click(play_sound, output_window, None)
|
231 |
+
output_window.change(set_speak, output_window, speak_dialog)
|
232 |
+
demo.queue().launch(share=True)
|