Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -36,7 +36,10 @@ def chat_with_audio(user_input, history):
|
|
| 36 |
)
|
| 37 |
}
|
| 38 |
|
| 39 |
-
messages = [system_prompt]
|
|
|
|
|
|
|
|
|
|
| 40 |
messages.append({"role": "user", "content": user_input})
|
| 41 |
|
| 42 |
response_text = query_groq(messages)
|
|
@@ -46,7 +49,7 @@ def chat_with_audio(user_input, history):
|
|
| 46 |
audio_file = f"/tmp/{uuid.uuid4()}.mp3"
|
| 47 |
tts.save(audio_file)
|
| 48 |
|
| 49 |
-
return response_text,
|
| 50 |
|
| 51 |
# Gradio ChatInterface with audio output
|
| 52 |
with gr.Blocks(theme="soft") as demo:
|
|
@@ -57,10 +60,11 @@ with gr.Blocks(theme="soft") as demo:
|
|
| 57 |
state = gr.State([])
|
| 58 |
|
| 59 |
def user_message(user_input, history):
|
| 60 |
-
reply,
|
| 61 |
-
|
|
|
|
| 62 |
|
| 63 |
msg.submit(user_message, [msg, state], [chatbot, state, audio])
|
| 64 |
|
| 65 |
# Launch the app
|
| 66 |
-
demo.launch(
|
|
|
|
| 36 |
)
|
| 37 |
}
|
| 38 |
|
| 39 |
+
messages = [system_prompt]
|
| 40 |
+
for user, assistant in history:
|
| 41 |
+
messages.append({"role": "user", "content": user})
|
| 42 |
+
messages.append({"role": "assistant", "content": assistant})
|
| 43 |
messages.append({"role": "user", "content": user_input})
|
| 44 |
|
| 45 |
response_text = query_groq(messages)
|
|
|
|
| 49 |
audio_file = f"/tmp/{uuid.uuid4()}.mp3"
|
| 50 |
tts.save(audio_file)
|
| 51 |
|
| 52 |
+
return response_text, audio_file
|
| 53 |
|
| 54 |
# Gradio ChatInterface with audio output
|
| 55 |
with gr.Blocks(theme="soft") as demo:
|
|
|
|
| 60 |
state = gr.State([])
|
| 61 |
|
| 62 |
def user_message(user_input, history):
|
| 63 |
+
reply, audio_path = chat_with_audio(user_input, history)
|
| 64 |
+
history.append([user_input, reply])
|
| 65 |
+
return history, history, audio_path
|
| 66 |
|
| 67 |
msg.submit(user_message, [msg, state], [chatbot, state, audio])
|
| 68 |
|
| 69 |
# Launch the app
|
| 70 |
+
demo.launch()
|