kk20krishna commited on
Commit
3983130
·
verified ·
1 Parent(s): 11a2104

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -27
app.py CHANGED
@@ -10,19 +10,15 @@ from Gradio_UI import GradioUI
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): The stock ticker symbol (e.g., "INFY" for Infosys).
18
 
19
  Returns:
20
- dict: A dictionary containing:
21
- - "Stock" (str): Stock symbol.
22
- - "Date" (str): The date of the last trading data.
23
- - "Current Price" (float): The latest closing price.
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")
@@ -32,25 +28,10 @@ def get_stock_price(stock_symbol: str) -> dict:
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')
36
- current_price = latest_data['Close']
37
-
38
- # Get previous close safely
39
- if len(data) > 1:
40
- previous_close = data['Close'].iloc[-2] # Use last available close
41
- else:
42
- previous_close = latest_data['Open'] # Fallback
43
-
44
- price_change = current_price - previous_close
45
- percent_change = (price_change / previous_close) * 100
46
-
47
- return {
48
- "Stock": stock_symbol,
49
- "Date": stock_date,
50
- "Current Price": round(current_price, 2),
51
- "Price Change": round(price_change, 2),
52
- "% Change": round(percent_change, 2)
53
- }
54
 
55
 
56
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
 
10
  import yfinance as yf
11
 
12
  @tool
13
+ def get_stock_price(stock_symbol: str) -> str:
14
+ """Fetch the current stock price.
15
 
16
  Args:
17
  stock_symbol (str): The stock ticker symbol (e.g., "INFY" for Infosys).
18
 
19
  Returns:
20
+ Currnet Price (str): Current price of the stock
21
+
 
 
 
 
22
  """
23
  stock_symbol = stock_symbol.upper() # Ensure uppercase
24
  stock = yf.Ticker(stock_symbol + ".NS")
 
28
  return {"error": f"No data found for {stock_symbol}."}
29
 
30
  latest_data = data.iloc[-1]
31
+ current_price = round(latest_data['Close'], 2)
32
+
33
+ return current_price
34
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
 
37
  # Below is an example of a tool that does nothing. Amaze us with your creativity !