TCares commited on
Commit
4be198e
·
verified ·
1 Parent(s): fe566bb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -7
app.py CHANGED
@@ -8,8 +8,8 @@ from tools.final_answer import FinalAnswerTool
8
  from Gradio_UI import GradioUI
9
  from tools.visit_webpage import VisitWebpageTool
10
 
11
- MAX_STEPS = 15
12
- MAX_SEARCH_RESULTS = 10 # should be smaller than MAX_STEPS, as we potentially visit each result, and each visit costs one step
13
 
14
  ddg_search_tool = DuckDuckGoSearchTool(max_results=MAX_SEARCH_RESULTS)
15
 
@@ -29,6 +29,31 @@ def find_job_websites(job:str, location:str)-> str:
29
 
30
  return results
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  @tool
33
  def get_current_time_in_timezone(timezone: str) -> str:
34
  """A tool that fetches the current local time in a specified timezone.
@@ -45,7 +70,7 @@ def get_current_time_in_timezone(timezone: str) -> str:
45
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
46
 
47
 
48
- visit_webpage = VisitWebpageTool()
49
  final_answer = FinalAnswerTool()
50
 
51
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
@@ -59,9 +84,6 @@ custom_role_conversions=None,
59
  )
60
 
61
 
62
- # Import tool from Hub
63
- image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
64
-
65
  with open("prompts.yaml", 'r') as stream:
66
  prompt_templates = yaml.safe_load(stream)
67
 
@@ -69,7 +91,7 @@ agent = CodeAgent(
69
  model=model,
70
  tools=[
71
  find_job_websites,
72
- visit_webpage,
73
  final_answer
74
  ],
75
  max_steps=MAX_STEPS,
 
8
  from Gradio_UI import GradioUI
9
  from tools.visit_webpage import VisitWebpageTool
10
 
11
+ MAX_STEPS = 8
12
+ MAX_SEARCH_RESULTS = 5 # should be smaller than MAX_STEPS, as we potentially visit each result, and each visit costs one step
13
 
14
  ddg_search_tool = DuckDuckGoSearchTool(max_results=MAX_SEARCH_RESULTS)
15
 
 
29
 
30
  return results
31
 
32
+ visit_webpage = VisitWebpageTool()
33
+
34
+
35
+ # 2. Text Summarizer
36
+ summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
37
+ def text_summarizer(text: str) -> str:
38
+ try:
39
+ summary = summarizer(text, max_length=1000, min_length=20, do_sample=False)
40
+ return summary[0]['summary_text']
41
+ except Exception as e:
42
+ return f"Error in summarization: {str(e)}"
43
+
44
+ @tool
45
+ def visit_webpage_summarization(url:str)-> str:
46
+ """A tool that visits a webpage at the given url and, reads its content as a markdown string,
47
+ and extracts relevant information. Use this to browse webpages.
48
+ Args:
49
+ url: The url of the webpage to visit.
50
+ Returns:
51
+ A summarization containing all relevant information about the webpage's content.
52
+ """
53
+ content = visit_webpage(url)
54
+
55
+ return text_summarizer(content)
56
+
57
  @tool
58
  def get_current_time_in_timezone(timezone: str) -> str:
59
  """A tool that fetches the current local time in a specified timezone.
 
70
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
71
 
72
 
73
+
74
  final_answer = FinalAnswerTool()
75
 
76
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
 
84
  )
85
 
86
 
 
 
 
87
  with open("prompts.yaml", 'r') as stream:
88
  prompt_templates = yaml.safe_load(stream)
89
 
 
91
  model=model,
92
  tools=[
93
  find_job_websites,
94
+ visit_webpage_summarization,
95
  final_answer
96
  ],
97
  max_steps=MAX_STEPS,