# ============================================================================ # app.py - FRONTEND # ============================================================================ import gradio as gr # Import backend functions and state management from research_agent import process_message # ============================================================================ # GRADIO APP DEFINITION # ============================================================================ with gr.Blocks(title="Deep Research Agent") as demo: # ============================================================================ # UI HEADER # ============================================================================ gr.Markdown("# 🔬 Deep Research Assistant") gr.Markdown(""" ### How it works 1. Enter a research topic 2. The AI asks clarification questions 3. You answer them 4. The system performs deep research using RAG + Web 5. A structured report is generated """) # ============================================================================ # UI COMPONENTS # ============================================================================ # Session state to track conversation across interactions state = gr.State() # API Keys Section gr.Markdown("### API Configuration") with gr.Row(): openai_api_key = gr.Textbox( label="OpenAI API Key", type="password", placeholder="Enter your OpenAI API key...", ) tavily_api_key = gr.Textbox( label="Tavily API Key", type="password", placeholder="Enter your Tavily API key...", ) # Research Settings Section gr.Markdown("### Research Settings") max_iterations = gr.Slider( label="Research Depth (number of research loops)", minimum=1, maximum=10, step=1, value=2, info="Number of research loops to perform. Note: 2 means one loop of the research node" ) # Chatbot interface component chatbot = gr.Chatbot() # User input textbox user_input = gr.Textbox( placeholder="Enter your research topic or clarification...", lines=2, label="Your Message" ) # Submit button submit = gr.Button("Send") # ============================================================================ # EVENT HANDLERS # ============================================================================ # Wire button to processing function from backend submit.click( process_message, # Imported from research_agent.py inputs=[user_input, chatbot, state, openai_api_key, tavily_api_key, max_iterations], outputs=[user_input, chatbot, state] ) # ============================================================================ # APPLICATION ENTRY POINT # ============================================================================ if __name__ == "__main__": demo.launch()