-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.py
More file actions
64 lines (50 loc) · 1.95 KB
/
gui.py
File metadata and controls
64 lines (50 loc) · 1.95 KB
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
# Simple Gradio GUI
# Ramy-ibrahim-Ahmed
import gradio as gr
from langchain_core.messages import HumanMessage
from src.agent import GRAPH
RECURSION_LIMIT = 15
async def run_agent_interaction(query: str) -> str:
if not query:
return "Please enter a research query."
config = {"recursion_limit": RECURSION_LIMIT}
try:
final_state = await GRAPH.ainvoke(
{"messages": HumanMessage(content=query)}, config=config
)
messages = final_state.get("messages", [])
last_message = messages[-1] if messages else None
report_text = final_state.get("report_text")
if report_text:
return f"**Report Generated:**\n\n---\n\n{report_text}"
elif last_message:
return f"**Agent Finished:**\n\n---\n\n[{last_message.name}]\n{last_message.content}"
else:
return "**Agent Finished:**\n\n---\n\nAgent finished, but the final state is unclear."
except Exception as e:
return (
f"**Error:**\n\n---\n\nAn error occurred during agent execution: {str(e)}"
)
with gr.Blocks(theme=gr.themes.Soft(), title="Research Bot") as iface:
gr.Markdown("# 🔍Electronic Market Research Bot")
gr.Markdown("Enter your query below to generate an electronics research report.")
with gr.Row():
query_input = gr.Textbox(
label="Research Query",
placeholder="e.g., Compare the latest iPhone Pro Max vs Samsung Galaxy Ultra camera...",
lines=3,
show_copy_button=True,
)
run_button = gr.Button("Run Research", variant="primary")
with gr.Row():
output_display = gr.Markdown(label="Agent Response")
run_button.click(
fn=run_agent_interaction,
inputs=[query_input],
outputs=[output_display],
)
gr.Markdown("---")
gr.Markdown(
"Note: Report generation can take some time depending on the complexity."
)
iface.launch(share=False)