Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,29 @@ from tools.final_answer import FinalAnswerTool
|
|
7 |
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
@tool
|
11 |
def get_current_time_in_timezone(timezone: str) -> str:
|
12 |
"""A tool that fetches the current local time in a specified timezone.
|
@@ -100,7 +123,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
100 |
|
101 |
agent = CodeAgent(
|
102 |
model=model,
|
103 |
-
tools=[final_answer,get_weather,image_generation_tool,get_current_time_in_timezone,DuckDuckGoSearchTool()], ## add your tools here (don't remove final answer)
|
104 |
max_steps=6,
|
105 |
verbosity_level=1,
|
106 |
grammar=None,
|
|
|
7 |
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
10 |
+
import yfinance as yf
|
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 |
+
|
20 |
+
stock_symbol = stock_symbol.upper() # Ensure uppercase
|
21 |
+
stock = yf.Ticker(stock_symbol + ".NS")
|
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.
|
|
|
123 |
|
124 |
agent = CodeAgent(
|
125 |
model=model,
|
126 |
+
tools=[final_answer,get_stock_price,get_weather,image_generation_tool,get_current_time_in_timezone,DuckDuckGoSearchTool()], ## add your tools here (don't remove final answer)
|
127 |
max_steps=6,
|
128 |
verbosity_level=1,
|
129 |
grammar=None,
|