Spaces:
Sleeping
Sleeping
Update app.py
Browse filestool get_current_stock_price added
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import requests
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
|
@@ -33,6 +34,35 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
final_answer = FinalAnswerTool()
|
| 37 |
|
| 38 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
|
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
+
import yfinance as yf
|
| 8 |
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
|
|
|
| 34 |
except Exception as e:
|
| 35 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 36 |
|
| 37 |
+
@tool
|
| 38 |
+
def get_current_stock_price(ticker_symbol: str) -> float:
|
| 39 |
+
"""
|
| 40 |
+
Fetches the latest stock price for the given ticker symbol.
|
| 41 |
+
|
| 42 |
+
Args:
|
| 43 |
+
ticker_symbol: The stock ticker symbol to fetch the price for.
|
| 44 |
+
|
| 45 |
+
Returns:
|
| 46 |
+
float: The current stock price of the given ticker symbol.
|
| 47 |
+
"""
|
| 48 |
+
try:
|
| 49 |
+
stock = yf.Ticker(ticker_symbol)
|
| 50 |
+
stock_data = stock.history(period="1d")
|
| 51 |
+
|
| 52 |
+
if stock_data.empty:
|
| 53 |
+
logger.warning(f"No data available for ticker symbol: {ticker_symbol}")
|
| 54 |
+
return None
|
| 55 |
+
|
| 56 |
+
current_price = stock_data['Close'].iloc[-1] # Get the most recent close price
|
| 57 |
+
|
| 58 |
+
return float(current_price)
|
| 59 |
+
|
| 60 |
+
except yf.exceptions.YFinanceException as yf_err:
|
| 61 |
+
logger.error(f"YFinance error for {ticker_symbol}: {str(yf_err)}")
|
| 62 |
+
except Exception as e:
|
| 63 |
+
logger.error(f"Unexpected error fetching price for {ticker_symbol}: {str(e)}")
|
| 64 |
+
return None
|
| 65 |
+
|
| 66 |
final_answer = FinalAnswerTool()
|
| 67 |
|
| 68 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|