Umer797 commited on
Commit
4a191bd
·
verified ·
1 Parent(s): daec8ef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -1
app.py CHANGED
@@ -32,6 +32,25 @@ def get_current_time_in_timezone(timezone: str) -> str:
32
  return f"The current local time in {timezone} is: {local_time}"
33
  except Exception as e:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
 
37
  final_answer = FinalAnswerTool()
@@ -55,7 +74,12 @@ with open("prompts.yaml", 'r') as stream:
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer], ## add your tools here (don't remove final answer)
 
 
 
 
 
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
@@ -66,4 +90,5 @@ agent = CodeAgent(
66
  )
67
 
68
 
 
69
  GradioUI(agent).launch()
 
32
  return f"The current local time in {timezone} is: {local_time}"
33
  except Exception as e:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
+
36
+ def wikipedia_summary(topic: str) -> str:
37
+ """Fetches a summary for a given topic from Wikipedia.
38
+ Args:
39
+ topic: The topic to search on Wikipedia.
40
+ """
41
+ try:
42
+ import wikipedia
43
+ # Set language to English
44
+ wikipedia.set_lang("en")
45
+ # Get summary of the topic
46
+ summary = wikipedia.summary(topic, sentences=3)
47
+ return f"📚 Wikipedia Summary:\n{summary}"
48
+ except wikipedia.exceptions.DisambiguationError as e:
49
+ return f"❗ The topic '{topic}' is ambiguous. Options include: {e.options[:5]}"
50
+ except wikipedia.exceptions.PageError:
51
+ return f"❗ No page found for '{topic}'. Please check the spelling."
52
+ except Exception as e:
53
+ return f"⚠️ Unexpected error: {str(e)}"
54
 
55
 
56
  final_answer = FinalAnswerTool()
 
74
 
75
  agent = CodeAgent(
76
  model=model,
77
+ tools=[
78
+ final_answer,
79
+ wikipedia_summary, # 👈 Add this
80
+ get_current_time_in_timezone, # Optional: if you want to keep it
81
+ image_generation_tool # Optional: if you want image gen
82
+ ],
83
  max_steps=6,
84
  verbosity_level=1,
85
  grammar=None,
 
90
  )
91
 
92
 
93
+
94
  GradioUI(agent).launch()