Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -547,42 +547,38 @@ def build_gradio_interface():
|
|
| 547 |
conversation_state = gr.State([])
|
| 548 |
|
| 549 |
# Function to process audio and update conversation
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
# Update conversation history
|
| 558 |
-
if "transcription" in result and "response" in result:
|
| 559 |
-
# Add new conversation turn
|
| 560 |
-
conversation_history.append({
|
| 561 |
-
"user": result["transcription"],
|
| 562 |
-
"bot": result["response"]
|
| 563 |
-
})
|
| 564 |
-
|
| 565 |
-
# Format the conversation as markdown
|
| 566 |
-
markdown = "## Conversation\n\n"
|
| 567 |
-
for turn in conversation_history:
|
| 568 |
-
markdown += f"**You:** {turn['user']}\n\n"
|
| 569 |
-
markdown += f"**Bot:** {turn['bot']}\n\n"
|
| 570 |
-
|
| 571 |
-
return markdown, conversation_history
|
| 572 |
-
else:
|
| 573 |
-
# If there was an error
|
| 574 |
-
error_msg = result.get("error", "Unknown error")
|
| 575 |
-
return f"**Error:** {error_msg}", conversation_history
|
| 576 |
-
|
| 577 |
-
# Event handler for real-time audio
|
| 578 |
-
audio_input.change(
|
| 579 |
-
process_and_update,
|
| 580 |
-
inputs=[audio_input, api_key_input, caller_id_input, conversation_state],
|
| 581 |
-
outputs=[conversation_display, conversation_state]
|
| 582 |
-
)
|
| 583 |
|
| 584 |
-
|
| 585 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 586 |
|
| 587 |
def clear_conversation():
|
| 588 |
return "*Conversation will appear here*", []
|
|
|
|
| 547 |
conversation_state = gr.State([])
|
| 548 |
|
| 549 |
# Function to process audio and update conversation
|
| 550 |
+
# Updates to the process_and_update function in the test interface section
|
| 551 |
+
|
| 552 |
+
def process_and_update(audio, api_key, caller_id, conversation_history):
|
| 553 |
+
# Check for required parameters
|
| 554 |
+
if not api_key:
|
| 555 |
+
return "**Error:** API key is required.", conversation_history
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 556 |
|
| 557 |
+
if audio is None:
|
| 558 |
+
return "*Conversation will appear here*", conversation_history
|
| 559 |
+
|
| 560 |
+
# Process the audio
|
| 561 |
+
result = process_voice_interaction(audio, api_key, caller_id)
|
| 562 |
+
|
| 563 |
+
# Update conversation history
|
| 564 |
+
if result.get("success") and "transcription" in result and "response" in result:
|
| 565 |
+
# Add new conversation turn
|
| 566 |
+
conversation_history.append({
|
| 567 |
+
"user": result["transcription"],
|
| 568 |
+
"bot": result["response"]
|
| 569 |
+
})
|
| 570 |
+
|
| 571 |
+
# Format the conversation as markdown
|
| 572 |
+
markdown = "## Conversation\n\n"
|
| 573 |
+
for turn in conversation_history:
|
| 574 |
+
markdown += f"**You:** {turn['user']}\n\n"
|
| 575 |
+
markdown += f"**Bot:** {turn['bot']}\n\n"
|
| 576 |
+
|
| 577 |
+
return markdown, conversation_history
|
| 578 |
+
else:
|
| 579 |
+
# If there was an error
|
| 580 |
+
error_msg = result.get("error", "Unknown error")
|
| 581 |
+
return f"**Error:** {error_msg}", conversation_history
|
| 582 |
|
| 583 |
def clear_conversation():
|
| 584 |
return "*Conversation will appear here*", []
|