""" OWL Web Interface This module implements the Gradio-based web interface for the OWL system. """ import gradio as gr from typing import Dict, Any from owl.agents.agent import OwlRolePlaying, AgentRole from owl.toolkits.web import WebToolkit from owl.toolkits.document import DocumentToolkit def create_app() -> gr.Blocks: """Create and configure the Gradio web interface.""" # Initialize agent roles user_role = AgentRole( name="User", description="A user seeking assistance with tasks", capabilities=["Task description", "Context provision", "Result validation"] ) assistant_role = AgentRole( name="Assistant", description="An AI assistant that helps accomplish tasks", capabilities=["Task analysis", "Tool selection", "Task execution"] ) # Initialize toolkits toolkits = [ WebToolkit(), DocumentToolkit() ] # Create role-playing session owl_session = OwlRolePlaying( user_role=user_role, assistant_role=assistant_role, toolkits=toolkits ) def process_input( user_input: str, history: list ) -> tuple[list, str]: """Process user input and update chat history.""" try: # Process input through OWL system result = owl_session.process_user_input(user_input) # Update history history.append((user_input, result["response"])) # Return updated history and empty input return history, "" except Exception as e: return history + [(user_input, f"Error: {str(e)}")], "" # Create Gradio interface with gr.Blocks(title="OWL - Optimized Workforce Learning") as app: gr.Markdown(""" # 🦉 OWL - Optimized Workforce Learning Welcome to OWL, your intelligent task automation assistant. """) with gr.Row(): with gr.Column(scale=4): chatbot = gr.Chatbot( label="Conversation", height=500 ) with gr.Row(): input_text = gr.Textbox( label="Your task or question", placeholder="Describe your task here...", lines=3 ) submit_btn = gr.Button("Submit") # Handle interactions submit_btn.click( fn=process_input, inputs=[input_text, chatbot], outputs=[chatbot, input_text] ) input_text.submit( fn=process_input, inputs=[input_text, chatbot], outputs=[chatbot, input_text] ) return app