Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,98 +1,101 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import gradio as gr
|
| 3 |
-
from crewai import Agent, Task, Crew, Process
|
| 4 |
-
from langchain_together import ChatTogether
|
| 5 |
-
from agents.web_crawler_agent import WebCrawlerAgent
|
| 6 |
-
from agents.summarizer_agent import SummarizerAgent
|
| 7 |
-
from agents.report_generator_agent import ReportGeneratorAgent
|
| 8 |
-
from dotenv import load_dotenv
|
| 9 |
-
|
| 10 |
-
load_dotenv()
|
| 11 |
-
|
| 12 |
-
model = os.getenv("MODEL_NAME")
|
| 13 |
-
os.environ['OPENAI_API_KEY'] = os.getenv("OPENAI_API_KEY")
|
| 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 |
-
with gr.Row():
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
|
|
|
|
|
|
|
|
|
| 98 |
demo.launch()
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from crewai import Agent, Task, Crew, Process
|
| 4 |
+
from langchain_together import ChatTogether
|
| 5 |
+
from agents.web_crawler_agent import WebCrawlerAgent
|
| 6 |
+
from agents.summarizer_agent import SummarizerAgent
|
| 7 |
+
from agents.report_generator_agent import ReportGeneratorAgent
|
| 8 |
+
from dotenv import load_dotenv
|
| 9 |
+
|
| 10 |
+
load_dotenv()
|
| 11 |
+
|
| 12 |
+
model = os.getenv("MODEL_NAME")
|
| 13 |
+
os.environ['OPENAI_API_KEY'] = os.getenv("OPENAI_API_KEY")
|
| 14 |
+
os.environ['LANGCHAIN_TRACING_V2'] = "true"
|
| 15 |
+
os.environ['LANGCHAIN_API_KEY'] = os.getenv("LANGCHAIN_API_KEY")
|
| 16 |
+
os.environ['LANGCHAIN_PROJECT'] = "KnowledgeKeeper"
|
| 17 |
+
|
| 18 |
+
llm = ChatTogether(model=model)
|
| 19 |
+
|
| 20 |
+
web_crawler_agent = WebCrawlerAgent(
|
| 21 |
+
llm=llm,
|
| 22 |
+
role="web crawler",
|
| 23 |
+
backstory="I search the web to gather information on a given topic.",
|
| 24 |
+
goal="Fetch web search results for a given query.",
|
| 25 |
+
serper_api_key=os.getenv("SERPER_API_KEY")
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
summarizer_agent = SummarizerAgent(llm)
|
| 30 |
+
|
| 31 |
+
report_generator_agent = ReportGeneratorAgent(llm=llm)
|
| 32 |
+
|
| 33 |
+
def generate_report(query, report_style):
|
| 34 |
+
web_crawler_task = Task(
|
| 35 |
+
description=query,
|
| 36 |
+
expected_output="A detailed response about the query.",
|
| 37 |
+
agent=web_crawler_agent
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
summarizer_task = Task(
|
| 41 |
+
description="Summarize the web data.",
|
| 42 |
+
expected_output="Concise summaries of the search results.",
|
| 43 |
+
agent=summarizer_agent
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
report_task = Task(
|
| 47 |
+
description=f"Generate a final research report in '{report_style}' style by removing bias if any.",
|
| 48 |
+
expected_output="A comprehensive research report.",
|
| 49 |
+
agent=report_generator_agent
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
crew = Crew(
|
| 53 |
+
agents=[web_crawler_agent, summarizer_agent, report_generator_agent],
|
| 54 |
+
tasks=[web_crawler_task, summarizer_task, report_task],
|
| 55 |
+
verbose=True,
|
| 56 |
+
process=Process.sequential,
|
| 57 |
+
context_flow={
|
| 58 |
+
"summarizer_task": "web_crawler_task",
|
| 59 |
+
"report_task": "summarizer_task",
|
| 60 |
+
}
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
result = crew.kickoff()
|
| 64 |
+
formatted_report = f"###### Report Generated in {report_style} Style:\n\n{result.raw}"
|
| 65 |
+
|
| 66 |
+
return formatted_report
|
| 67 |
+
|
| 68 |
+
with gr.Blocks() as demo:
|
| 69 |
+
gr.Markdown("## π Research Report Generation and Analysis Tool")
|
| 70 |
+
gr.Markdown("#### Enter your query and choose the report style to generate a detailed, formatted report!")
|
| 71 |
+
|
| 72 |
+
with gr.Row():
|
| 73 |
+
query_input = gr.Textbox(
|
| 74 |
+
label="Enter Your Query",
|
| 75 |
+
placeholder="e.g., Recent advancements in Indian Agriculture",
|
| 76 |
+
lines=2,
|
| 77 |
+
elem_id="query-input"
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
with gr.Row():
|
| 81 |
+
report_style = gr.Radio(
|
| 82 |
+
choices=[ "Detailed Analysis", "Brief Summary","Bullet Points"],
|
| 83 |
+
label="Select Report Style",
|
| 84 |
+
value="Detailed Analysis"
|
| 85 |
+
)
|
| 86 |
+
|
| 87 |
+
with gr.Row():
|
| 88 |
+
generate_button = gr.Button("Generate Report", elem_id="generate-button", variant="primary")
|
| 89 |
+
|
| 90 |
+
with gr.Row():
|
| 91 |
+
report_output = gr.Markdown(
|
| 92 |
+
label="Generated Report"
|
| 93 |
+
)
|
| 94 |
+
|
| 95 |
+
generate_button.click(
|
| 96 |
+
generate_report,
|
| 97 |
+
inputs=[query_input, report_style],
|
| 98 |
+
outputs=[report_output]
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
demo.launch()
|