dromerosm commited on
Commit
200e087
1 Parent(s): 4dd415f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -13
app.py CHANGED
@@ -1,15 +1,16 @@
1
  import os
2
  import gradio as gr
 
3
  from crewai import Agent, Task, Crew
4
  from langchain_groq import ChatGroq
5
  from langchain_community.tools import DuckDuckGoSearchRun, DuckDuckGoSearchResults
6
  from crewai_tools import tool, SeleniumScrapingTool, ScrapeWebsiteTool
7
 
8
  # Define the DuckDuckGoSearch tool using the decorator for tool registration
9
- @tool('DuckDuckGoSearch')
10
- def search(search_query: str):
11
- """Search the web for information on a given topic."""
12
- return DuckDuckGoSearchRun().run(search_query)
13
 
14
  # Define the DuckDuckGoSearch tool
15
  @tool('DuckDuckGoResults')
@@ -32,16 +33,39 @@ def search_results(search_query: str):
32
  """
33
  return DuckDuckGoSearchResults().run(search_query)
34
 
 
 
 
35
 
36
- # Define the WebScrapper tool
37
  @tool('WebScrapper')
38
- def web_scrapper(url: str):
39
  """
40
- A tool designed to extract and read the content of a specified link.
41
  It is capable of handling various types of web pages by making HTTP requests and parsing the received HTML content.
42
- This tool can be particularly useful for web scraping tasks, data collection, or extracting specific information from websites.
 
 
 
 
 
43
  """
44
- return ScrapeWebsiteTool(website_url=url)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
  def kickoff_crew(topic: str) -> dict:
47
  try:
@@ -53,13 +77,12 @@ def kickoff_crew(topic: str) -> dict:
53
 
54
  # Initialize the Groq large language model
55
  groq_llm_70b = ChatGroq(temperature=0, groq_api_key=groq_api_key, model_name="llama3-70b-8192")
56
- groq_llm_8b = ChatGroq(temperature=0, groq_api_key=groq_api_key, model_name="llama3-8b-8192")
57
 
58
  # Define Agents with Groq LLM
59
  researcher = Agent(
60
  role='Researcher',
61
  goal='Collect detailed information on {topic}',
62
- tools=[search, search_results, web_scrapper],
63
  llm=groq_llm_70b, # Assigning the Groq LLM here
64
  backstory=(
65
  "As a diligent researcher, you explore the depths of the internet to "
@@ -94,8 +117,7 @@ def kickoff_crew(topic: str) -> dict:
94
  # Define Tasks
95
  research_task = Task(
96
  description=(
97
- "Use DuckDuckGoSearch tool to gather initial information about {topic}. "
98
- "Next, employ DuckDuckGoResults tool to gather full details of the insights from search results, reading them carefully and preparing detailed summaries on {topic}. "
99
  "Utilize the WebScrapper tool to extract additional information and insights from all links or URLs that appear significant regarding {topic} after analyzing the snippets of the search results. "
100
  "Compile your findings into an initial draft, ensuring to include all sources with their titles and links relevant to the topic. "
101
  "Throughout this process, maintain a high standard of accuracy and ensure that no information is fabricated or misrepresented."
 
1
  import os
2
  import gradio as gr
3
+ import cohere
4
  from crewai import Agent, Task, Crew
5
  from langchain_groq import ChatGroq
6
  from langchain_community.tools import DuckDuckGoSearchRun, DuckDuckGoSearchResults
7
  from crewai_tools import tool, SeleniumScrapingTool, ScrapeWebsiteTool
8
 
9
  # Define the DuckDuckGoSearch tool using the decorator for tool registration
10
+ # @tool('DuckDuckGoSearch')
11
+ # def search(search_query: str):
12
+ # """Search the web for information on a given topic."""
13
+ # return DuckDuckGoSearchRun().run(search_query)
14
 
15
  # Define the DuckDuckGoSearch tool
16
  @tool('DuckDuckGoResults')
 
33
  """
34
  return DuckDuckGoSearchResults().run(search_query)
35
 
36
+ # Retrieve the Cohere API key from environment variables
37
+ cohere_api_key = os.getenv('COHERE_API_KEY')
38
+ co = cohere.Client(cohere_api_key)
39
 
 
40
  @tool('WebScrapper')
41
+ def web_scrapper(url: str, topic: str):
42
  """
43
+ A tool designed to extract and read the content of a specified link and generate a summary on a specific topic.
44
  It is capable of handling various types of web pages by making HTTP requests and parsing the received HTML content.
45
+ This tool uses Cohere's API to generate summaries, which can be particularly useful for web scraping tasks, data collection,
46
+ or extracting specific information from websites.
47
+
48
+ Args:
49
+ - url (str): The URL from which to scrape content.
50
+ - topic (str): The specific topic on which to generate a summary.
51
  """
52
+ # Scrape content from the specified URL
53
+ scraper = ScrapeWebsiteTool(website_url=url)
54
+ content = scraper.run()
55
+
56
+ # Prepare the prompt for generating the summary
57
+ prompt = f"Generate a summary of the following content on the topic ## {topic} ### \n\nCONTENT:\n\n" + content
58
+
59
+ # Generate the summary using Cohere
60
+ response = co.chat(
61
+ model='command-r-plus',
62
+ message=prompt,
63
+ temperature=0.2,
64
+ chat_history=[],
65
+ prompt_truncation='AUTO'
66
+ )
67
+
68
+ return response.text
69
 
70
  def kickoff_crew(topic: str) -> dict:
71
  try:
 
77
 
78
  # Initialize the Groq large language model
79
  groq_llm_70b = ChatGroq(temperature=0, groq_api_key=groq_api_key, model_name="llama3-70b-8192")
 
80
 
81
  # Define Agents with Groq LLM
82
  researcher = Agent(
83
  role='Researcher',
84
  goal='Collect detailed information on {topic}',
85
+ tools=[search_results, web_scrapper],
86
  llm=groq_llm_70b, # Assigning the Groq LLM here
87
  backstory=(
88
  "As a diligent researcher, you explore the depths of the internet to "
 
117
  # Define Tasks
118
  research_task = Task(
119
  description=(
120
+ "Use DuckDuckGoResults tool to gather full details of the insights from search results about ## {topic} ##, reading them carefully and preparing detailed summaries on {topic}. "
 
121
  "Utilize the WebScrapper tool to extract additional information and insights from all links or URLs that appear significant regarding {topic} after analyzing the snippets of the search results. "
122
  "Compile your findings into an initial draft, ensuring to include all sources with their titles and links relevant to the topic. "
123
  "Throughout this process, maintain a high standard of accuracy and ensure that no information is fabricated or misrepresented."