Spaces:
Runtime error
Runtime error
File size: 3,061 Bytes
d32b98d 083214f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | # ============================================================================
# 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() |