ahmedaman commited on
Commit
c4d63b8
·
verified ·
1 Parent(s): de82666

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -6,7 +6,7 @@ import yaml
6
  from tools.final_answer import FinalAnswerTool
7
 
8
  from Gradio_UI import GradioUI
9
- import wikipedia
10
 
11
  @tool
12
  def wikipedia_summary(topic: str) -> str:
@@ -20,13 +20,14 @@ def wikipedia_summary(topic: str) -> str:
20
  Returns:
21
  str: A summary of the Wikipedia article.
22
  """
23
- try:
24
- summary = wikipedia.summary(topic, sentences=3)
25
- return summary
26
- except wikipedia.exceptions.DisambiguationError as e:
27
- return f"Topic is ambiguous. Did you mean: {', '.join(e.options[:5])}?"
28
- except wikipedia.exceptions.PageError:
29
- return "No matching Wikipedia page found."
 
30
 
31
  @tool
32
  def get_current_time_in_timezone(timezone: str) -> str:
 
6
  from tools.final_answer import FinalAnswerTool
7
 
8
  from Gradio_UI import GradioUI
9
+ import wikipediaapi
10
 
11
  @tool
12
  def wikipedia_summary(topic: str) -> str:
 
20
  Returns:
21
  str: A summary of the Wikipedia article.
22
  """
23
+ wiki = wikipediaapi.Wikipedia(language="en", user_agent="MyWikipediaBot/1.0")
24
+ page = wiki.page(topic)
25
+
26
+ if page.exists():
27
+ page_content = page.summary
28
+ return page_content
29
+ else:
30
+ return "Page not found"
31
 
32
  @tool
33
  def get_current_time_in_timezone(timezone: str) -> str: