Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,49 @@ from tools.final_answer import FinalAnswerTool
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
def current_temprature_in_planet(planet: str) -> str:
|
|
@@ -54,7 +97,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 54 |
|
| 55 |
agent = CodeAgent(
|
| 56 |
model=model,
|
| 57 |
-
tools=[current_temprature_in_planet, final_answer], ## add your tools here (don't remove final answer)
|
| 58 |
max_steps=6,
|
| 59 |
verbosity_level=1,
|
| 60 |
grammar=None,
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
+
import yfinance as yf
|
| 11 |
+
|
| 12 |
+
def get_nse_stock_price(stock_symbol: str) -> dict:
|
| 13 |
+
"""
|
| 14 |
+
Fetch the latest NSE stock price, price change, and percentage change.
|
| 15 |
+
Use NSE ticker symbol.
|
| 16 |
+
|
| 17 |
+
Args:
|
| 18 |
+
stock_symbol (str): NSE Stock symbol of the company (e.g., 'RELIANCE', 'INFY').
|
| 19 |
+
|
| 20 |
+
Returns:
|
| 21 |
+
dict: Stock details including date, current price, price change, and percentage change.
|
| 22 |
+
"""
|
| 23 |
+
try:
|
| 24 |
+
stock_symbol = stock_symbol.upper() # Ensure uppercase
|
| 25 |
+
stock = yf.Ticker(stock_symbol + ".NS")
|
| 26 |
+
data = stock.history(period='5d') # Get last 5 days to handle non-trading days
|
| 27 |
+
|
| 28 |
+
if data.empty:
|
| 29 |
+
return {"error": f"No data found for {stock_symbol} on NSE."}
|
| 30 |
+
|
| 31 |
+
latest_data = data.iloc[-1]
|
| 32 |
+
stock_date = latest_data.name.strftime('%Y-%m-%d')
|
| 33 |
+
current_price = latest_data['Close']
|
| 34 |
+
|
| 35 |
+
# Get previous close safely
|
| 36 |
+
if len(data) > 1:
|
| 37 |
+
previous_close = data['Close'].iloc[-2] # Use last available close
|
| 38 |
+
else:
|
| 39 |
+
previous_close = latest_data['Open'] # Fallback
|
| 40 |
+
|
| 41 |
+
price_change = current_price - previous_close
|
| 42 |
+
percent_change = (price_change / previous_close) * 100
|
| 43 |
+
|
| 44 |
+
return {
|
| 45 |
+
"Stock": stock_symbol,
|
| 46 |
+
"Date": stock_date,
|
| 47 |
+
"Current Price": round(current_price, 2),
|
| 48 |
+
"Price Change": round(price_change, 2),
|
| 49 |
+
"% Change": round(percent_change, 2)
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
|
| 53 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 54 |
@tool
|
| 55 |
def current_temprature_in_planet(planet: str) -> str:
|
|
|
|
| 97 |
|
| 98 |
agent = CodeAgent(
|
| 99 |
model=model,
|
| 100 |
+
tools=[get_nse_stock_price, current_temprature_in_planet, final_answer], ## add your tools here (don't remove final answer)
|
| 101 |
max_steps=6,
|
| 102 |
verbosity_level=1,
|
| 103 |
grammar=None,
|