Yudum commited on
Commit
de547c9
·
verified ·
1 Parent(s): 7bc755d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -20
app.py CHANGED
@@ -7,36 +7,31 @@ from tools.final_answer import FinalAnswerTool
7
 
8
  from Gradio_UI import GradioUI
9
 
10
- import wikipedia
11
-
12
  @tool
13
- def generate_image_from_wikipedia(topic: str) -> str:
14
  """
15
- Fetches a summary of a given topic and generates an image based on it.
16
 
17
  Args:
18
- topic (str): The topic to search for in Wikipedia. It should be a short phrase like "Albert Einstein" or "The Great Wall of China".
19
 
20
  Returns:
21
- str: A URL or path to the generated image.
22
  """
23
  try:
24
- # Set Wikipedia language to Turkish
25
- wikipedia.set_lang("tr")
26
-
27
- # Get a short summary from Wikipedia
28
- summary = wikipedia.summary(topic, sentences=2)
29
-
30
- # Generate an image based on the summary
31
- image = image_generation_tool(summary)
32
 
33
- return image
34
-
35
- except wikipedia.exceptions.DisambiguationError as e:
36
- return f"Multiple topics found: {e.options[:5]}... Please specify further."
37
- except wikipedia.exceptions.PageError:
38
- return f"Sorry, no Wikipedia page was found for '{topic}'."
39
 
 
 
40
 
41
  @tool
42
  def get_current_time_in_timezone(timezone: str) -> str:
 
7
 
8
  from Gradio_UI import GradioUI
9
 
 
 
10
  @tool
11
+ def fetch_duckduckgo_summary(query: str) -> str:
12
  """
13
+ Fetches a short summary from web search results.
14
 
15
  Args:
16
+ query (str): The search query.
17
 
18
  Returns:
19
+ str: A brief summary of the top search results.
20
  """
21
  try:
22
+ # Perform a DuckDuckGo search
23
+ search_tool = DuckDuckGoSearchTool()
24
+ search_results = search_tool(query=query, max_results=3)
 
 
 
 
 
25
 
26
+ # Extract the top results
27
+ if search_results and isinstance(search_results, list):
28
+ summary = "\n".join([f"{res['title']}: {res.get('body', 'No description')}" for res in search_results])
29
+ return summary
30
+ else:
31
+ return "No relevant results found."
32
 
33
+ except Exception as e:
34
+ return f"Error fetching search results: {str(e)}"
35
 
36
  @tool
37
  def get_current_time_in_timezone(timezone: str) -> str: