Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,12 +10,11 @@ from Gradio_UI import GradioUI
|
|
| 10 |
import yfinance as yf
|
| 11 |
|
| 12 |
@tool
|
| 13 |
-
def
|
| 14 |
-
"""
|
| 15 |
-
Fetch the latest NSE stock price, price change, and percentage change.
|
| 16 |
|
| 17 |
Args:
|
| 18 |
-
|
| 19 |
|
| 20 |
Returns:
|
| 21 |
dict: A dictionary containing:
|
|
@@ -25,12 +24,12 @@ def get_nse_stock_price(stock_name: str) -> dict:
|
|
| 25 |
- "Price Change" (float): The price difference from the previous close.
|
| 26 |
- "% Change" (float): The percentage change from the previous close.
|
| 27 |
"""
|
| 28 |
-
|
| 29 |
-
stock = yf.Ticker(
|
| 30 |
data = stock.history(period='5d') # Get last 5 days to handle non-trading days
|
| 31 |
|
| 32 |
if data.empty:
|
| 33 |
-
return {"error": f"No data found for {stock_symbol}
|
| 34 |
|
| 35 |
latest_data = data.iloc[-1]
|
| 36 |
stock_date = latest_data.name.strftime('%Y-%m-%d')
|
|
@@ -101,7 +100,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 101 |
|
| 102 |
agent = CodeAgent(
|
| 103 |
model=model,
|
| 104 |
-
tools=[
|
| 105 |
max_steps=6,
|
| 106 |
verbosity_level=1,
|
| 107 |
grammar=None,
|
|
|
|
| 10 |
import yfinance as yf
|
| 11 |
|
| 12 |
@tool
|
| 13 |
+
def get_stock_price(stock_symbol: str) -> dict:
|
| 14 |
+
"""Fetch the latest stock price, date, current Price, price change, and percentage change.
|
|
|
|
| 15 |
|
| 16 |
Args:
|
| 17 |
+
stock_symbol (str): Symbol of the stock
|
| 18 |
|
| 19 |
Returns:
|
| 20 |
dict: A dictionary containing:
|
|
|
|
| 24 |
- "Price Change" (float): The price difference from the previous close.
|
| 25 |
- "% Change" (float): The percentage change from the previous close.
|
| 26 |
"""
|
| 27 |
+
stock_symbol = stock_symbol.upper() # Ensure uppercase
|
| 28 |
+
stock = yf.Ticker(stock_symbol + ".NS")
|
| 29 |
data = stock.history(period='5d') # Get last 5 days to handle non-trading days
|
| 30 |
|
| 31 |
if data.empty:
|
| 32 |
+
return {"error": f"No data found for {stock_symbol}."}
|
| 33 |
|
| 34 |
latest_data = data.iloc[-1]
|
| 35 |
stock_date = latest_data.name.strftime('%Y-%m-%d')
|
|
|
|
| 100 |
|
| 101 |
agent = CodeAgent(
|
| 102 |
model=model,
|
| 103 |
+
tools=[get_stock_price, current_temprature_in_planet, final_answer], ## add your tools here (don't remove final answer)
|
| 104 |
max_steps=6,
|
| 105 |
verbosity_level=1,
|
| 106 |
grammar=None,
|