Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -24,6 +24,8 @@ else:
|
|
24 |
dp.mkdir(exist_ok=True)
|
25 |
dataDir = '/data/'
|
26 |
|
|
|
|
|
27 |
client = OpenAI(api_key = key)
|
28 |
|
29 |
def genUsageStats(do_reset=False):
|
@@ -174,6 +176,24 @@ def transcribe(user, pwd, fpath):
|
|
174 |
def pause_message():
|
175 |
return "Audio input is paused. Resume or Stop as desired"
|
176 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
177 |
with gr.Blocks() as demo:
|
178 |
history = gr.State([])
|
179 |
password = gr.State("")
|
@@ -196,6 +216,7 @@ with gr.Blocks() as demo:
|
|
196 |
# gpt_chooser=gr.Radio(choices=[("GPT-3.5","gpt-3.5-turbo"),("GPT-4o","gpt-4o-mini")],
|
197 |
# value="gpt-3.5-turbo", label="GPT Model", interactive=True)
|
198 |
submit_window = gr.Button(value="Submit Prompt/Question")
|
|
|
199 |
prompt_window = gr.Textbox(label = "Prompt or Question")
|
200 |
output_window = gr.Textbox(label = "Dialog")
|
201 |
submit_window.click(chat, inputs=[prompt_window, user_window, password, history, output_window, model],
|
@@ -205,4 +226,8 @@ with gr.Blocks() as demo:
|
|
205 |
outputs=[prompt_window])
|
206 |
audio_widget.pause_recording(fn=pause_message, outputs=[prompt_window])
|
207 |
reset_button.add(audio_widget)
|
|
|
|
|
|
|
|
|
208 |
demo.launch(share=True)
|
|
|
24 |
dp.mkdir(exist_ok=True)
|
25 |
dataDir = '/data/'
|
26 |
|
27 |
+
speak_file = dataDir + "speek.wav"
|
28 |
+
|
29 |
client = OpenAI(api_key = key)
|
30 |
|
31 |
def genUsageStats(do_reset=False):
|
|
|
176 |
def pause_message():
|
177 |
return "Audio input is paused. Resume or Stop as desired"
|
178 |
|
179 |
+
def gen_output_audio(txt):
|
180 |
+
if len(txt) < 10:
|
181 |
+
txt = "This dialog is too short to mess with!"
|
182 |
+
response = client.audio.speech.create(model="tts-1", voice="fable", input=txt)
|
183 |
+
with open(speak_file, 'wb') as fp:
|
184 |
+
fp.write(response.content)
|
185 |
+
return speak_file
|
186 |
+
|
187 |
+
def set_speak_button(txt):
|
188 |
+
vis = False
|
189 |
+
if len(txt) > 10:
|
190 |
+
vis = True
|
191 |
+
return gr.Button(visible=vis)
|
192 |
+
|
193 |
+
def delete_speak_file():
|
194 |
+
if os.path.exists(speak_file):
|
195 |
+
os.remove(speak_file)
|
196 |
+
|
197 |
with gr.Blocks() as demo:
|
198 |
history = gr.State([])
|
199 |
password = gr.State("")
|
|
|
216 |
# gpt_chooser=gr.Radio(choices=[("GPT-3.5","gpt-3.5-turbo"),("GPT-4o","gpt-4o-mini")],
|
217 |
# value="gpt-3.5-turbo", label="GPT Model", interactive=True)
|
218 |
submit_window = gr.Button(value="Submit Prompt/Question")
|
219 |
+
speak_output = gr.Button(value="Speak Dialog", visible=False)
|
220 |
prompt_window = gr.Textbox(label = "Prompt or Question")
|
221 |
output_window = gr.Textbox(label = "Dialog")
|
222 |
submit_window.click(chat, inputs=[prompt_window, user_window, password, history, output_window, model],
|
|
|
226 |
outputs=[prompt_window])
|
227 |
audio_widget.pause_recording(fn=pause_message, outputs=[prompt_window])
|
228 |
reset_button.add(audio_widget)
|
229 |
+
audio_out = gr.Audio(autoplay=True, visible=False)
|
230 |
+
speak_output.click(gen_output_audio, output_window, audio_out)
|
231 |
+
output_window.change(fn=set_speak_button, inputs=output_window,outputs=speak_output)
|
232 |
+
demo.unload(delete_speak_file)
|
233 |
demo.launch(share=True)
|