Spaces:
Running
Running
Commit Β·
f061fb0
1
Parent(s): 5fc9eb5
images and working in legislation tab
Browse files
src/pictures/185161-004-EAF28842.jpg
DELETED
|
Binary file (44.1 kB)
|
|
|
src/ui/tabs/legislation_tab.py
CHANGED
|
@@ -57,8 +57,8 @@ def create_legislation_tab():
|
|
| 57 |
label="π¬ Conversation with EU Legislation Expert",
|
| 58 |
height=500,
|
| 59 |
show_label=True,
|
| 60 |
-
avatar_images=(None, "π€")
|
| 61 |
-
|
| 62 |
)
|
| 63 |
|
| 64 |
with gr.Row():
|
|
|
|
| 57 |
label="π¬ Conversation with EU Legislation Expert",
|
| 58 |
height=500,
|
| 59 |
show_label=True,
|
| 60 |
+
avatar_images=(None, "π€")
|
| 61 |
+
# Gradio 6 uses message format by default: {"role": "user/assistant", "content": "..."}
|
| 62 |
)
|
| 63 |
|
| 64 |
with gr.Row():
|
src/utils/elevenlabs_agent.py
CHANGED
|
@@ -54,9 +54,13 @@ class EULegislationAgent:
|
|
| 54 |
self.conversation = Conversation(
|
| 55 |
client=self.client,
|
| 56 |
agent_id=AGENT_ID,
|
|
|
|
|
|
|
| 57 |
# Add any additional configuration here
|
| 58 |
**AGENT_CONFIG
|
| 59 |
)
|
|
|
|
|
|
|
| 60 |
return True
|
| 61 |
except Exception as e:
|
| 62 |
print(f"Error starting conversation: {e}")
|
|
@@ -79,14 +83,21 @@ class EULegislationAgent:
|
|
| 79 |
return "β Error: Could not connect to the agent. Please check your API key and Agent ID."
|
| 80 |
|
| 81 |
# Send message and get response
|
| 82 |
-
response = self.conversation.
|
| 83 |
|
| 84 |
# Extract text from response
|
|
|
|
| 85 |
if hasattr(response, 'text'):
|
| 86 |
return response.text
|
| 87 |
-
elif isinstance(response, dict)
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
else:
|
|
|
|
| 90 |
return str(response)
|
| 91 |
|
| 92 |
except Exception as e:
|
|
@@ -110,9 +121,9 @@ class EULegislationAgent:
|
|
| 110 |
"""End the current conversation."""
|
| 111 |
if self.conversation:
|
| 112 |
try:
|
| 113 |
-
self.conversation.
|
| 114 |
-
except:
|
| 115 |
-
|
| 116 |
self.conversation = None
|
| 117 |
|
| 118 |
|
|
|
|
| 54 |
self.conversation = Conversation(
|
| 55 |
client=self.client,
|
| 56 |
agent_id=AGENT_ID,
|
| 57 |
+
requires_auth=False, # Set to True if your agent requires authentication
|
| 58 |
+
audio_interface=None, # Set to an audio interface if using voice
|
| 59 |
# Add any additional configuration here
|
| 60 |
**AGENT_CONFIG
|
| 61 |
)
|
| 62 |
+
# Start the session
|
| 63 |
+
self.conversation.start_session()
|
| 64 |
return True
|
| 65 |
except Exception as e:
|
| 66 |
print(f"Error starting conversation: {e}")
|
|
|
|
| 83 |
return "β Error: Could not connect to the agent. Please check your API key and Agent ID."
|
| 84 |
|
| 85 |
# Send message and get response
|
| 86 |
+
response = self.conversation.send_user_message(message)
|
| 87 |
|
| 88 |
# Extract text from response
|
| 89 |
+
# The response might be a generator or have different formats
|
| 90 |
if hasattr(response, 'text'):
|
| 91 |
return response.text
|
| 92 |
+
elif isinstance(response, dict):
|
| 93 |
+
if 'text' in response:
|
| 94 |
+
return response['text']
|
| 95 |
+
elif 'content' in response:
|
| 96 |
+
return response['content']
|
| 97 |
+
elif isinstance(response, str):
|
| 98 |
+
return response
|
| 99 |
else:
|
| 100 |
+
# Try to convert to string
|
| 101 |
return str(response)
|
| 102 |
|
| 103 |
except Exception as e:
|
|
|
|
| 121 |
"""End the current conversation."""
|
| 122 |
if self.conversation:
|
| 123 |
try:
|
| 124 |
+
self.conversation.end_session()
|
| 125 |
+
except Exception as e:
|
| 126 |
+
print(f"Error ending conversation: {e}")
|
| 127 |
self.conversation = None
|
| 128 |
|
| 129 |
|