Update app.py
Browse files
app.py
CHANGED
|
@@ -1,30 +1,77 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
demo = gr.Interface(
|
| 19 |
-
fn=
|
| 20 |
inputs=gr.Textbox(
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
outputs=gr.Textbox(
|
| 24 |
-
label="Generated Report"
|
| 25 |
),
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
)
|
| 29 |
|
| 30 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import time
|
| 3 |
|
| 4 |
+
class PlannerAgent:
|
| 5 |
+
def run(self, query):
|
| 6 |
+
return {
|
| 7 |
+
"goal": query,
|
| 8 |
+
"tasks": [
|
| 9 |
+
"Understand the topic",
|
| 10 |
+
"Collect important information",
|
| 11 |
+
"Generate final report"
|
| 12 |
+
]
|
| 13 |
+
}
|
| 14 |
|
| 15 |
+
class ResearchAgent:
|
| 16 |
+
def run(self, plan):
|
| 17 |
+
topic = plan["goal"]
|
| 18 |
|
| 19 |
+
research = f"""
|
| 20 |
+
Topic: {topic}
|
| 21 |
|
| 22 |
+
Key Points:
|
| 23 |
+
• Definition and overview
|
| 24 |
+
• Major applications
|
| 25 |
+
• Advantages
|
| 26 |
+
• Challenges
|
| 27 |
+
• Future scope
|
| 28 |
+
"""
|
| 29 |
+
return research
|
| 30 |
+
|
| 31 |
+
class WriterAgent:
|
| 32 |
+
def run(self, research):
|
| 33 |
+
report = f"""
|
| 34 |
+
# AI Generated Report
|
| 35 |
+
|
| 36 |
+
{research}
|
| 37 |
+
|
| 38 |
+
Conclusion:
|
| 39 |
+
This report summarizes the important aspects of the topic and provides a concise overview.
|
| 40 |
+
"""
|
| 41 |
+
return report
|
| 42 |
+
|
| 43 |
+
planner = PlannerAgent()
|
| 44 |
+
researcher = ResearchAgent()
|
| 45 |
+
writer = WriterAgent()
|
| 46 |
+
|
| 47 |
+
def multi_agent_workflow(query):
|
| 48 |
+
|
| 49 |
+
if not query.strip():
|
| 50 |
+
return "Please enter a topic."
|
| 51 |
+
|
| 52 |
+
plan = planner.run(query)
|
| 53 |
+
time.sleep(1)
|
| 54 |
+
|
| 55 |
+
research = researcher.run(plan)
|
| 56 |
+
time.sleep(1)
|
| 57 |
+
|
| 58 |
+
final_report = writer.run(research)
|
| 59 |
+
|
| 60 |
+
return final_report
|
| 61 |
|
| 62 |
demo = gr.Interface(
|
| 63 |
+
fn=multi_agent_workflow,
|
| 64 |
inputs=gr.Textbox(
|
| 65 |
+
lines=2,
|
| 66 |
+
placeholder="Enter any topic..."
|
|
|
|
|
|
|
| 67 |
),
|
| 68 |
+
outputs=gr.Markdown(),
|
| 69 |
+
title="Multi-Agent AI Research Assistant",
|
| 70 |
+
description="""
|
| 71 |
+
Planner Agent → Research Agent → Writer Agent
|
| 72 |
+
|
| 73 |
+
Enter a topic and the agents will collaborate to generate a report.
|
| 74 |
+
"""
|
| 75 |
)
|
| 76 |
|
| 77 |
demo.launch()
|