Samagra07 commited on
Commit
ac8fc9c
Β·
verified Β·
1 Parent(s): f9e5853

Update app.py

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