Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -130,21 +130,58 @@ def model(text, web_search):
|
|
130 |
stream = client1.text_generation(formatted_prompt, max_new_tokens=300, stream=True, details=True, return_full_text=False)
|
131 |
return "".join([response.token.text for response in stream if response.token.text != "</s>"])
|
132 |
|
133 |
-
async def respond(audio, web_search):
|
134 |
user = transcribe(audio)
|
135 |
reply = model(user, web_search)
|
136 |
-
communicate = edge_tts.Communicate(reply)
|
137 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
|
138 |
tmp_path = tmp_file.name
|
139 |
await communicate.save(tmp_path)
|
140 |
-
return tmp_path
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
|
149 |
if __name__ == "__main__":
|
150 |
-
demo.queue(max_size=200).launch()
|
|
|
130 |
stream = client1.text_generation(formatted_prompt, max_new_tokens=300, stream=True, details=True, return_full_text=False)
|
131 |
return "".join([response.token.text for response in stream if response.token.text != "</s>"])
|
132 |
|
133 |
+
async def respond(audio, web_search, voice):
|
134 |
user = transcribe(audio)
|
135 |
reply = model(user, web_search)
|
136 |
+
communicate = edge_tts.Communicate(reply, voice=voice)
|
137 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
|
138 |
tmp_path = tmp_file.name
|
139 |
await communicate.save(tmp_path)
|
140 |
+
return tmp_path, user, reply
|
141 |
+
|
142 |
+
# List of available voices for edge_tts
|
143 |
+
voices = ["en-US-JennyNeural", "en-US-GuyNeural", "en-GB-SoniaNeural", "en-AU-NatashaNeural"]
|
144 |
+
|
145 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
146 |
+
gr.Markdown("# ποΈ **OpenGPT 4o - Advanced Voice Assistant**")
|
147 |
+
with gr.Tabs():
|
148 |
+
with gr.TabItem("Conversation"):
|
149 |
+
with gr.Row():
|
150 |
+
with gr.Column():
|
151 |
+
audio_input = gr.Audio(label="π€ Speak or Upload Audio", sources="microphone", type="filepath")
|
152 |
+
web_search = gr.Checkbox(label="π Enable Web Search", value=False)
|
153 |
+
voice = gr.Dropdown(label="π€ Choose Voice", choices=voices, value="en-US-JennyNeural")
|
154 |
+
submit_btn = gr.Button("π Submit")
|
155 |
+
with gr.Column():
|
156 |
+
audio_output = gr.Audio(label="π€ AI Response", autoplay=True)
|
157 |
+
user_text = gr.Textbox(label="π€ You Said", interactive=False)
|
158 |
+
ai_text = gr.Textbox(label="π€ AI Response", interactive=False)
|
159 |
+
|
160 |
+
with gr.TabItem("History"):
|
161 |
+
history = gr.Dataframe(headers=["User Input", "AI Response"], interactive=False)
|
162 |
+
|
163 |
+
with gr.TabItem("Settings"):
|
164 |
+
gr.Markdown("### βοΈ Settings")
|
165 |
+
max_tokens = gr.Slider(minimum=50, maximum=500, value=300, label="Max Tokens")
|
166 |
+
temperature = gr.Slider(minimum=0.1, maximum=1.0, value=0.7, label="Temperature")
|
167 |
+
gr.Markdown("Adjust the parameters to customize the AI's behavior.")
|
168 |
+
|
169 |
+
# Store conversation history
|
170 |
+
conversation_history = []
|
171 |
+
|
172 |
+
def update_history(user_input, ai_response):
|
173 |
+
conversation_history.append([user_input, ai_response])
|
174 |
+
return conversation_history
|
175 |
+
|
176 |
+
submit_btn.click(
|
177 |
+
fn=respond,
|
178 |
+
inputs=[audio_input, web_search, voice],
|
179 |
+
outputs=[audio_output, user_text, ai_text]
|
180 |
+
).then(
|
181 |
+
fn=update_history,
|
182 |
+
inputs=[user_text, ai_text],
|
183 |
+
outputs=history
|
184 |
+
)
|
185 |
|
186 |
if __name__ == "__main__":
|
187 |
+
demo.queue(max_size=200).launch()
|