Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,69 +1,96 @@
|
|
| 1 |
-
# ============================================================================
|
| 2 |
-
# app.py - FRONTEND
|
| 3 |
-
# ============================================================================
|
| 4 |
-
|
| 5 |
-
import gradio as gr
|
| 6 |
-
|
| 7 |
-
# Import backend functions and state management
|
| 8 |
-
from research_agent import process_message
|
| 9 |
-
|
| 10 |
-
# ============================================================================
|
| 11 |
-
# GRADIO APP DEFINITION
|
| 12 |
-
# ============================================================================
|
| 13 |
-
|
| 14 |
-
with gr.Blocks(title="Deep Research Agent") as demo:
|
| 15 |
-
|
| 16 |
-
# ============================================================================
|
| 17 |
-
# UI HEADER
|
| 18 |
-
# ============================================================================
|
| 19 |
-
|
| 20 |
-
gr.Markdown("# 🔬 Deep Research Assistant")
|
| 21 |
-
|
| 22 |
-
gr.Markdown("""
|
| 23 |
-
### How it works
|
| 24 |
-
|
| 25 |
-
1. Enter a research topic
|
| 26 |
-
2. The AI asks clarification questions
|
| 27 |
-
3. You answer them
|
| 28 |
-
4. The system performs deep research using RAG + Web
|
| 29 |
-
5. A structured report is generated
|
| 30 |
-
""")
|
| 31 |
-
|
| 32 |
-
# ============================================================================
|
| 33 |
-
# UI COMPONENTS
|
| 34 |
-
# ============================================================================
|
| 35 |
-
|
| 36 |
-
# Session state to track conversation across interactions
|
| 37 |
-
state = gr.State()
|
| 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 |
demo.launch()
|
|
|
|
| 1 |
+
# ============================================================================
|
| 2 |
+
# app.py - FRONTEND
|
| 3 |
+
# ============================================================================
|
| 4 |
+
|
| 5 |
+
import gradio as gr
|
| 6 |
+
|
| 7 |
+
# Import backend functions and state management
|
| 8 |
+
from research_agent import process_message
|
| 9 |
+
|
| 10 |
+
# ============================================================================
|
| 11 |
+
# GRADIO APP DEFINITION
|
| 12 |
+
# ============================================================================
|
| 13 |
+
|
| 14 |
+
with gr.Blocks(title="Deep Research Agent") as demo:
|
| 15 |
+
|
| 16 |
+
# ============================================================================
|
| 17 |
+
# UI HEADER
|
| 18 |
+
# ============================================================================
|
| 19 |
+
|
| 20 |
+
gr.Markdown("# 🔬 Deep Research Assistant")
|
| 21 |
+
|
| 22 |
+
gr.Markdown("""
|
| 23 |
+
### How it works
|
| 24 |
+
|
| 25 |
+
1. Enter a research topic
|
| 26 |
+
2. The AI asks clarification questions
|
| 27 |
+
3. You answer them
|
| 28 |
+
4. The system performs deep research using RAG + Web
|
| 29 |
+
5. A structured report is generated
|
| 30 |
+
""")
|
| 31 |
+
|
| 32 |
+
# ============================================================================
|
| 33 |
+
# UI COMPONENTS
|
| 34 |
+
# ============================================================================
|
| 35 |
+
|
| 36 |
+
# Session state to track conversation across interactions
|
| 37 |
+
state = gr.State()
|
| 38 |
+
|
| 39 |
+
# API Keys Section
|
| 40 |
+
gr.Markdown("### API Configuration")
|
| 41 |
+
|
| 42 |
+
with gr.Row():
|
| 43 |
+
openai_api_key = gr.Textbox(
|
| 44 |
+
label="OpenAI API Key",
|
| 45 |
+
type="password",
|
| 46 |
+
placeholder="Enter your OpenAI API key...",
|
| 47 |
+
)
|
| 48 |
+
tavily_api_key = gr.Textbox(
|
| 49 |
+
label="Tavily API Key",
|
| 50 |
+
type="password",
|
| 51 |
+
placeholder="Enter your Tavily API key...",
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
# Research Settings Section
|
| 55 |
+
gr.Markdown("### Research Settings")
|
| 56 |
+
|
| 57 |
+
max_iterations = gr.Slider(
|
| 58 |
+
label="Research Depth (number of research loops)",
|
| 59 |
+
minimum=1,
|
| 60 |
+
maximum=10,
|
| 61 |
+
step=1,
|
| 62 |
+
value=2,
|
| 63 |
+
info="Number of research loops to perform. Note: 2 means one loop of the research node"
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
# Chatbot interface component
|
| 67 |
+
chatbot = gr.Chatbot()
|
| 68 |
+
|
| 69 |
+
# User input textbox
|
| 70 |
+
user_input = gr.Textbox(
|
| 71 |
+
placeholder="Enter your research topic or clarification...",
|
| 72 |
+
lines=2,
|
| 73 |
+
label="Your Message"
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
# Submit button
|
| 77 |
+
submit = gr.Button("Send")
|
| 78 |
+
|
| 79 |
+
# ============================================================================
|
| 80 |
+
# EVENT HANDLERS
|
| 81 |
+
# ============================================================================
|
| 82 |
+
|
| 83 |
+
# Wire button to processing function from backend
|
| 84 |
+
submit.click(
|
| 85 |
+
process_message, # Imported from research_agent.py
|
| 86 |
+
inputs=[user_input, chatbot, state, openai_api_key, tavily_api_key, max_iterations],
|
| 87 |
+
outputs=[user_input, chatbot, state]
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
# ============================================================================
|
| 92 |
+
# APPLICATION ENTRY POINT
|
| 93 |
+
# ============================================================================
|
| 94 |
+
|
| 95 |
+
if __name__ == "__main__":
|
| 96 |
demo.launch()
|