import gradio as gr import os from agent import GenerativeAIAgent # Initialize the agent agent = GenerativeAIAgent() def chat_with_agent(user_input, history): """Chat function that maintains conversation history""" if not user_input.strip(): return history, history response = agent.generate_response(user_input) history.append((user_input, response)) return history, history # Create fancy Gradio interface with custom theme with gr.Blocks( theme=gr.themes.Soft( primary_hue="blue", secondary_hue="indigo", neutral_hue="slate", ), css=""" .gradio-container { font-family: 'Inter', sans-serif; } .chat-container { border-radius: 15px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); } footer { display: none !important; } """ ) as demo: gr.Markdown( """ # 🤖 AI Assistant with Tool Integration **Powered by GPT-5** • Ask anything and I'll use Wikipedia or web search to find accurate answers! --- """, elem_classes="header" ) with gr.Row(): with gr.Column(scale=1): gr.Markdown( """ ### 🛠️ Available Tools - 📚 **Wikipedia**: For factual information - 🌐 **Tavily Search**: For latest news & web content ### 💡 Try asking: - "What's the latest news about AI?" - "Tell me about quantum computing" - "Recent developments in climate change" """, elem_classes="sidebar" ) with gr.Column(scale=3): chatbot = gr.Chatbot( label="Conversation", height=500, bubble_full_width=False, avatar_images=(None, "assistant_avatar.png"), elem_classes="chat-container" ) with gr.Row(): user_input = gr.Textbox( label="Your Message", placeholder="Type your question here... 💬", lines=2, scale=4 ) submit_btn = gr.Button("Send 🚀", variant="primary", scale=1) with gr.Row(): clear_btn = gr.Button("Clear Chat 🗑️", variant="secondary") # Store conversation history state = gr.State([]) # Event handlers submit_btn.click( fn=chat_with_agent, inputs=[user_input, state], outputs=[chatbot, state] ).then( lambda: "", outputs=[user_input] ) user_input.submit( fn=chat_with_agent, inputs=[user_input, state], outputs=[chatbot, state] ).then( lambda: "", outputs=[user_input] ) clear_btn.click( lambda: ([], []), outputs=[chatbot, state] ) gr.Markdown( """ --- 🔒 **Privacy**: Your conversations are not stored • ⚡ **Fast**: Powered by OpenAI's latest models """, elem_classes="footer" ) # Launch the app demo.launch(share=False)