jaidesign commited on
Commit
9f83023
·
verified ·
1 Parent(s): ff45a91

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -92
app.py CHANGED
@@ -9,97 +9,6 @@ from Gradio_UI import GradioUI
9
 
10
 
11
 
12
- @tool
13
- def get_stock_price(stock_symbol: str) -> str:
14
- """A tool that fetches the current stock price for given stock symbol.
15
-
16
- Args:
17
- stock_symbol: A string representing a valid NYSE (USA) stock ticker symbol (e.g., "AAPL" for Apple Inc., Consumer Electronics, Market Cap $3,674.40B).
18
- """
19
- import yfinance as yf
20
- stock_symbol = stock_symbol.upper() # Ensure uppercase
21
- stock = yf.Ticker(stock_symbol + ".NYSE")
22
- data = stock.history(period='5d') # Get last 5 days to handle non-trading days
23
-
24
- if data.empty:
25
- return {"error": f"No data found for {stock_symbol}."}
26
-
27
- latest_data = data.iloc[-1]
28
- current_price = round(latest_data['Close'], 2)
29
-
30
- return current_price
31
-
32
-
33
- @tool
34
- def get_current_time_in_timezone(timezone: str) -> str:
35
- """A tool that fetches the current local time in a specified timezone.
36
-
37
- Args:
38
- timezone: A string representing a valid timezone (e.g., 'America/New_York').
39
-
40
- Returns:
41
- A string displaying the local date and time in the specified timezone.
42
- """
43
- try:
44
- # Validate timezone
45
- if timezone not in pytz.all_timezones:
46
- return f"❌ Error: '{timezone}' is not a valid timezone. Please provide a correct timezone (e.g., 'America/New_York')."
47
-
48
- # Get the current time in the specified timezone
49
- tz = pytz.timezone(timezone)
50
- local_time = datetime.datetime.now(tz)
51
-
52
- # Format the output with day, date, and time
53
- formatted_time = local_time.strftime("%A, %Y-%m-%d %H:%M:%S %Z")
54
-
55
- return f"🕒 The current local time in **{timezone}** is: **{formatted_time}**"
56
-
57
- except Exception as e:
58
- return f"⚠️ Error fetching time for timezone '{timezone}': {str(e)}"
59
-
60
- @tool
61
- def get_weather(location: str = None, zipcode: int = None) -> str:
62
- """Fetches the current weather for a specified location or zip code.
63
-
64
- Args:
65
- location: A string representing a valid city name or region (e.g., 'New York').
66
- zipcode: An integer representing a valid zip code (e.g., 10001 for NYC).
67
-
68
- Returns:
69
- A string describing the weather conditions, temperature, and humidity.
70
- """
71
- temperature = data["main"]["temp"]
72
- conditions = data["weather"][0]["description"]
73
- humidity = data["main"]["humidity"]
74
-
75
- return (f"🌤️ Weather in {location or zipcode} is: {conditions.capitalize()}, "
76
- f"Temperature: {temperature}°C, Humidity: {humidity}%")
77
-
78
- #return f"The current weather in {location,zipcode} is: {temperature,}"
79
-
80
-
81
- @tool
82
- def getMarsWeather() -> str:
83
- """
84
- A tool that fetches the current weather on Mars using NASA's InSight API.
85
- Returns:
86
- A string containing the sol (Martian day), average temperature, and wind speed on Mars.
87
- """
88
- insightURL = 'https://api.nasa.gov/insight_weather/?api_key={}&feedtype=json&ver=1.0'.format(NASA_API_KEY)
89
- response = requests.get(insightURL)
90
- marsWeatherRaw = response.json()
91
- firstKey = next(iter(marsWeatherRaw))
92
- marsWeather = {
93
- 'sol': firstKey,
94
- 'temperature': marsWeatherRaw[firstKey]['AT']['av'],
95
- 'wind_speed': marsWeatherRaw[firstKey]['HWS']['av']
96
- }
97
- outputStr = "The temperature on Mars on Sol {sol} is {temperature} C and wind speeds of {wind_speed} m/sec.".format(
98
- sol=marsWeather['sol'],
99
- temperature=marsWeather['temperature'],
100
- wind_speed=marsWeather['wind_speed'])
101
-
102
- return outputStr
103
 
104
  final_answer = FinalAnswerTool()
105
 
@@ -110,7 +19,7 @@ model = HfApiModel(
110
  max_tokens=2096,
111
  temperature=0.5,
112
  #model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
113
- model_id='meta-llama/Llama-3.2-3B-Instruct', # Here I used another model to compare the results
114
  custom_role_conversions=None,
115
  )
116
 
 
9
 
10
 
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  final_answer = FinalAnswerTool()
14
 
 
19
  max_tokens=2096,
20
  temperature=0.5,
21
  #model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
22
+ #model_id='meta-llama/Llama-3.2-3B-Instruct', # Here I used another model to compare the results
23
  custom_role_conversions=None,
24
  )
25