SaraM2727 commited on
Commit
ec648d9
·
verified ·
1 Parent(s): 6909370

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -7
app.py CHANGED
@@ -9,7 +9,15 @@ from Gradio_UI import GradioUI
9
  # Tool: Fetch current time in a given timezone
10
  @tool
11
  def get_current_time_in_timezone(timezone: str) -> str:
12
- """Fetches the current local time in a specified timezone."""
 
 
 
 
 
 
 
 
13
  try:
14
  tz = pytz.timezone(timezone)
15
  local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
@@ -20,7 +28,15 @@ def get_current_time_in_timezone(timezone: str) -> str:
20
  # Tool: Fetch real-time weather for a given location
21
  @tool
22
  def get_weather(city: str) -> str:
23
- """Fetches the current weather for a given city."""
 
 
 
 
 
 
 
 
24
  api_url = f"https://wttr.in/{city}?format=%C+%t"
25
  response = requests.get(api_url)
26
  if response.status_code == 200:
@@ -30,7 +46,16 @@ def get_weather(city: str) -> str:
30
  # Tool: Fetch currency exchange rate
31
  @tool
32
  def get_exchange_rate(base_currency: str, target_currency: str) -> str:
33
- """Fetches the exchange rate between two currencies."""
 
 
 
 
 
 
 
 
 
34
  url = f"https://api.exchangerate-api.com/v4/latest/{base_currency}"
35
  response = requests.get(url)
36
  if response.status_code == 200:
@@ -42,7 +67,15 @@ def get_exchange_rate(base_currency: str, target_currency: str) -> str:
42
  # Tool: Fetch Wikipedia summary
43
  @tool
44
  def get_wikipedia_summary(query: str) -> str:
45
- """Fetches a short summary from Wikipedia."""
 
 
 
 
 
 
 
 
46
  url = f"https://en.wikipedia.org/api/rest_v1/page/summary/{query}"
47
  response = requests.get(url)
48
  if response.status_code == 200:
@@ -52,7 +85,12 @@ def get_wikipedia_summary(query: str) -> str:
52
  # Tool: Fetch latest news headlines
53
  @tool
54
  def get_latest_news() -> str:
55
- """Fetches the latest news headlines."""
 
 
 
 
 
56
  url = "https://newsapi.org/v2/top-headlines?country=us&apiKey=YOUR_NEWSAPI_KEY"
57
  response = requests.get(url)
58
  if response.status_code == 200:
@@ -63,7 +101,15 @@ def get_latest_news() -> str:
63
  # Tool: Fetch stock price for a given company symbol
64
  @tool
65
  def get_stock_price(symbol: str) -> str:
66
- """Fetches the latest stock price for a given company symbol."""
 
 
 
 
 
 
 
 
67
  url = f"https://finnhub.io/api/v1/quote?symbol={symbol}&token=YOUR_FINNHUB_API_KEY"
68
  response = requests.get(url)
69
  if response.status_code == 200:
@@ -110,4 +156,4 @@ agent = CodeAgent(
110
  )
111
 
112
  # Launch Gradio UI for interaction
113
- GradioUI(agent).launch()
 
9
  # Tool: Fetch current time in a given timezone
10
  @tool
11
  def get_current_time_in_timezone(timezone: str) -> str:
12
+ """
13
+ Fetches the current local time in a specified timezone.
14
+
15
+ Args:
16
+ timezone (str): A string representing a valid timezone (e.g., 'America/New_York').
17
+
18
+ Returns:
19
+ str: The current time in the given timezone.
20
+ """
21
  try:
22
  tz = pytz.timezone(timezone)
23
  local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
 
28
  # Tool: Fetch real-time weather for a given location
29
  @tool
30
  def get_weather(city: str) -> str:
31
+ """
32
+ Fetches the current weather for a given city.
33
+
34
+ Args:
35
+ city (str): Name of the city.
36
+
37
+ Returns:
38
+ str: Weather description and temperature.
39
+ """
40
  api_url = f"https://wttr.in/{city}?format=%C+%t"
41
  response = requests.get(api_url)
42
  if response.status_code == 200:
 
46
  # Tool: Fetch currency exchange rate
47
  @tool
48
  def get_exchange_rate(base_currency: str, target_currency: str) -> str:
49
+ """
50
+ Fetches the exchange rate between two currencies.
51
+
52
+ Args:
53
+ base_currency (str): The currency to convert from.
54
+ target_currency (str): The currency to convert to.
55
+
56
+ Returns:
57
+ str: Exchange rate information.
58
+ """
59
  url = f"https://api.exchangerate-api.com/v4/latest/{base_currency}"
60
  response = requests.get(url)
61
  if response.status_code == 200:
 
67
  # Tool: Fetch Wikipedia summary
68
  @tool
69
  def get_wikipedia_summary(query: str) -> str:
70
+ """
71
+ Fetches a short summary from Wikipedia.
72
+
73
+ Args:
74
+ query (str): The topic to search on Wikipedia.
75
+
76
+ Returns:
77
+ str: Summary of the topic.
78
+ """
79
  url = f"https://en.wikipedia.org/api/rest_v1/page/summary/{query}"
80
  response = requests.get(url)
81
  if response.status_code == 200:
 
85
  # Tool: Fetch latest news headlines
86
  @tool
87
  def get_latest_news() -> str:
88
+ """
89
+ Fetches the latest news headlines.
90
+
91
+ Returns:
92
+ str: Top 5 latest news headlines.
93
+ """
94
  url = "https://newsapi.org/v2/top-headlines?country=us&apiKey=YOUR_NEWSAPI_KEY"
95
  response = requests.get(url)
96
  if response.status_code == 200:
 
101
  # Tool: Fetch stock price for a given company symbol
102
  @tool
103
  def get_stock_price(symbol: str) -> str:
104
+ """
105
+ Fetches the latest stock price for a given company symbol.
106
+
107
+ Args:
108
+ symbol (str): The stock ticker symbol.
109
+
110
+ Returns:
111
+ str: The latest stock price.
112
+ """
113
  url = f"https://finnhub.io/api/v1/quote?symbol={symbol}&token=YOUR_FINNHUB_API_KEY"
114
  response = requests.get(url)
115
  if response.status_code == 200:
 
156
  )
157
 
158
  # Launch Gradio UI for interaction
159
+ GradioUI(agent).launch()