samsonDzealot commited on
Commit
55a4d16
·
verified ·
1 Parent(s): ae7a494

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -9
app.py CHANGED
@@ -4,19 +4,48 @@ import requests
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
-
8
  from Gradio_UI import GradioUI
 
9
 
10
- # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
- def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
- #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that does nothing yet
15
  Args:
16
- arg1: the first argument
17
- arg2: the second argument
18
  """
19
- return "What magic will you build ?"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -55,7 +84,7 @@ 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,
 
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
 
7
  from Gradio_UI import GradioUI
8
+ from bs4 import BeautifulSoup
9
 
 
10
  @tool
11
+ def get_weather(city: str) -> str:
12
+ """A tool that fetches the current weather for a given city.
 
13
  Args:
14
+ city: A string representing the city name (e.g., 'New York').
 
15
  """
16
+ api_key = "8549c1b0e2c7d6cf8abe4407d739fdf2" # Replace with your key
17
+ url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric"
18
+ try:
19
+ response = requests.get(url)
20
+ data = response.json()
21
+ if data["cod"] != 200:
22
+ return f"Error: City '{city}' not found or API issue."
23
+ temp = data["main"]["temp"]
24
+ desc = data["weather"][0]["description"]
25
+ return f"Current weather in {city}: {temp}°C, {desc}."
26
+ except Exception as e:
27
+ return f"Error fetching weather for '{city}': {str(e)}"
28
+
29
+ # Trending Hashtags Tool (Scraping getdaytrends.com)
30
+ @tool
31
+ def get_trending_hashtags(location: str = "usa") -> str:
32
+ """A tool that fetches trending hashtags from getdaytrends.com for a given location.
33
+ Args:
34
+ location: A string representing the location (e.g., 'usa', 'uk'). Defaults to 'usa'.
35
+ """
36
+ try:
37
+ url = f"https://getdaytrends.com/{location.lower()}/"
38
+ response = requests.get(url)
39
+ if response.status_code != 200:
40
+ return f"Error: Couldn’t fetch trends for '{location}'."
41
+ soup = BeautifulSoup(response.text, "html.parser")
42
+ # Find trend items (adjust selector based on site - this is a guess, might need tweak)
43
+ trends = [tag.text.strip() for tag in soup.select("td a[href*='twitter.com']")[:5]]
44
+ if not trends:
45
+ return f"Error: No trends found for '{location}' - site might’ve changed."
46
+ return f"Top trending hashtags in {location}: {', '.join(trends)}"
47
+ except Exception as e:
48
+ return f"Error fetching trends for '{location}': {str(e)}"
49
 
50
  @tool
51
  def get_current_time_in_timezone(timezone: str) -> str:
 
84
 
85
  agent = CodeAgent(
86
  model=model,
87
+ tools=[final_answer, get_weather, get_trending_hashtags, get_current_time_in_timezone], ## add your tools here (don't remove final answer)
88
  max_steps=6,
89
  verbosity_level=1,
90
  grammar=None,