Alesmikes commited on
Commit
b6fce1d
1 Parent(s): c0a316a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -12
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
- messages = chat.generate_dialogue(audio)
72
- voice_path = chat.synthesize_voice(messages)
 
73
  chat_text = "\n".join([f"{msg['role']}: {msg['content']}" for msg in messages])
74
- return voice_path, chat_text
 
 
75
  #global messages
76
 
77
  """
@@ -128,12 +132,12 @@ def transcribe(audio):
128
 
129
  output_text = gr.outputs.Textbox(label="Chat Messages")
130
 
131
- output_audio = gr.outputs.Audio(label="Synthesized Voice")
132
- output_text = gr.outputs.Textbox(label="Chat Messages")
133
- gr.Interface(
134
- fn=transcribe,
135
- inputs=gr.inputs.Audio(source="microphone", label="Speak here..."),
136
- outputs=[output_audio, output_text],
137
- live=True,
138
- allow_flagging='never'
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()