rajkumarrawal's picture
Initial commit
2ec0d39
"""
Consumer Agent Gradio Application
Web interface for the Consumer Agent - Personal Concierge
"""
import gradio as gr
import asyncio
import logging
from .consumer_agent import ConsumerAgent
class ConsumerApp:
"""Gradio web application for Consumer Agent."""
def __init__(self):
self.agent = ConsumerAgent()
self.conversation_history = []
# Set up logging
logging.basicConfig(level=logging.INFO)
# Create the interface
self.interface = self._create_interface()
def _create_interface(self):
"""Create the Gradio interface."""
with gr.Blocks(
title="πŸ‘₯ Consumer Agent - Secure AI Suite",
theme=gr.themes.Soft(
primary_hue="green",
secondary_hue="gray",
neutral_hue="slate"
),
css="""
.container { max-width: 1200px; margin: auto; }
.chatbot { height: 500px; }
.status-card { background: linear-gradient(90deg, #4facfe 0%, #00f2fe 100%); color: white; }
.tool-card { border: 2px solid #e2e8f0; border-radius: 8px; padding: 12px; margin: 8px 0; }
"""
) as app:
# Header
gr.HTML("""
<div style='text-align: center; padding: 20px; background: linear-gradient(90deg, #4facfe 0%, #00f2fe 100%); color: white; border-radius: 10px;'>
<h1 style='margin: 0; font-size: 2.5em;'>πŸ‘₯ Consumer Agent</h1>
<p style='margin: 10px 0; font-size: 1.2em;'>Your Personal Concierge & Travel Assistant</p>
<p style='margin: 0; opacity: 0.8;'>πŸ” Secure AI Agents Suite</p>
</div>
""")
with gr.Row():
# Left column - Chat interface
with gr.Column(scale=2):
gr.HTML("<h3>πŸ’¬ Chat with Consumer Agent</h3>")
chatbot = gr.Chatbot(
label="Personal Concierge Assistant",
height=400,
elem_classes=["chatbot"],
avatar_images=(None, "πŸ‘₯")
)
with gr.Row():
msg_input = gr.Textbox(
placeholder="Ask me about trip planning, reminders, document summaries...",
lines=3,
max_lines=5,
label="Your Message"
)
with gr.Column(scale=0):
send_btn = gr.Button("Send", variant="primary")
clear_btn = gr.Button("Clear", variant="secondary")
# Right column - Tools and Quick Actions
with gr.Column(scale=1):
gr.HTML("<h3>πŸ› οΈ Available Services</h3>")
tools_info = gr.HTML("""
<div class="tool-card">
<h4>✈️ Trip Planning</h4>
<p>β€’ Plan complete itineraries<br>β€’ Search flights and hotels<br>β€’ Create travel budgets</p>
</div>
<div class="tool-card">
<h4>⏰ Reminders & Scheduling</h4>
<p>β€’ Set personalized alerts<br>β€’ Track upcoming events<br>β€’ Manage to-do lists</p>
</div>
<div class="tool-card">
<h4>πŸ“„ Document Helper</h4>
<p>β€’ Summarize documents<br>β€’ Extract key information<br>β€’ Organize important papers</p>
</div>
<div class="tool-card">
<h4>🌀️ Travel Assistant</h4>
<p>β€’ Check weather conditions<br>β€’ Track expenses<br>β€’ Plan activities</p>
</div>
""")
gr.HTML("<h3>πŸ“Š System Status</h3>")
status_display = gr.HTML()
# Event handlers
def user(user_message, history):
"""Handle user input."""
if not user_message.strip():
return history, ""
# Add user message to history
history.append((user_message, None))
return history, ""
async def bot_response(history, user_message):
"""Generate bot response."""
if not user_message.strip():
return history
# Get response from agent
response = await self.agent.handle_user_input(user_message)
# Add bot response to history
history[-1] = (user_message, response)
return history
def clear_conversation():
"""Clear conversation history."""
return []
def update_status():
"""Update status display."""
status = self.agent.get_status()
return f"""
<div class="status-card" style="padding: 15px; border-radius: 8px;">
<h4>βœ… System Status</h4>
<p><strong>Agent:</strong> {status['name']}</p>
<p><strong>Status:</strong> {status['status']}</p>
<p><strong>Security:</strong> {'πŸ›‘οΈ Enabled' if status['security_enabled'] else '❌ Disabled'}</p>
<p><strong>Audit Logging:</strong> {'πŸ“Š Enabled' if status['audit_logging'] else '❌ Disabled'}</p>
<p><strong>Services:</strong> {', '.join(status['tools'][:3])}...</p>
</div>
"""
# Connect events
send_btn.click(
user,
inputs=[msg_input, chatbot],
outputs=[chatbot, msg_input]
).then(
bot_response,
inputs=[chatbot, msg_input],
outputs=[chatbot]
)
msg_input.submit(
user,
inputs=[msg_input, chatbot],
outputs=[chatbot, msg_input]
).then(
bot_response,
inputs=[chatbot, msg_input],
outputs=[chatbot]
)
clear_btn.click(clear_conversation, outputs=chatbot)
# Initial status update
app.load(update_status, outputs=status_display)
return app
def launch(self, **kwargs):
"""Launch the Gradio application."""
self.interface.launch(
server_name="0.0.0.0",
server_port=7861,
share=False,
show_error=True,
quiet=False,
**kwargs
)
# Example usage and quick commands
EXAMPLE_QUERIES = [
"Plan a trip to Pokhara next week with medium budget",
"Remind me to call mom tomorrow at 3 PM",
"Summarize this email about project deadlines",
"What's the weather like in Kathmandu?",
"Search for hotels in Delhi for December",
"Show my travel itinerary for TRP001"
]
def main():
"""Main function to run the Consumer Agent app."""
print("πŸ‘₯ Starting Consumer Agent...")
print("πŸ—ΊοΈ Loading trip planning services...")
print("⏰ Setting up reminder system...")
print("πŸ“„ Initializing document processor...")
app = ConsumerApp()
print("\n" + "="*60)
print("πŸ‘₯ CONSUMER AGENT - PERSONAL CONCIERGE")
print("="*60)
print("\nπŸ’‘ Example requests you can try:")
for i, query in enumerate(EXAMPLE_QUERIES, 1):
print(f" {i}. {query}")
print("\n🌐 Starting Gradio server...")
print("πŸ”— Open your browser to: http://localhost:7861")
print("\n" + "="*60)
app.launch()
if __name__ == "__main__":
main()