Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,24 +14,27 @@ from Gradio_UI import GradioUI
|
|
| 14 |
@tool
|
| 15 |
def get_stock_price(company: str) -> str:
|
| 16 |
"""Fetches the current stock price of an Indian company using DuckDuckGo search.
|
|
|
|
| 17 |
Args:
|
| 18 |
company: The name or symbol of the company (e.g., 'Reliance', 'TCS')
|
|
|
|
|
|
|
|
|
|
| 19 |
"""
|
| 20 |
search_tool = DuckDuckGoSearchTool()
|
| 21 |
|
| 22 |
# Construct the search query
|
| 23 |
-
query = f"{company} stock price today
|
| 24 |
|
| 25 |
# Perform the search
|
| 26 |
search_results = search_tool(query)
|
| 27 |
-
|
| 28 |
-
# Extract stock price using regex (pattern for ₹ price)
|
| 29 |
-
match = re.search(r"([\d,]+\.?\d*)USD", search_results)
|
| 30 |
|
| 31 |
-
|
|
|
|
|
|
|
| 32 |
if match:
|
| 33 |
-
price = match.group(
|
| 34 |
-
return f"The current stock price of {company} is {price}."
|
| 35 |
else:
|
| 36 |
return f"Could not find the stock price for {company}. Please check manually."
|
| 37 |
|
|
|
|
| 14 |
@tool
|
| 15 |
def get_stock_price(company: str) -> str:
|
| 16 |
"""Fetches the current stock price of an Indian company using DuckDuckGo search.
|
| 17 |
+
|
| 18 |
Args:
|
| 19 |
company: The name or symbol of the company (e.g., 'Reliance', 'TCS')
|
| 20 |
+
|
| 21 |
+
Returns:
|
| 22 |
+
A string with the stock price or an error message.
|
| 23 |
"""
|
| 24 |
search_tool = DuckDuckGoSearchTool()
|
| 25 |
|
| 26 |
# Construct the search query
|
| 27 |
+
query = f"{company} stock price today India"
|
| 28 |
|
| 29 |
# Perform the search
|
| 30 |
search_results = search_tool(query)
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
+
# Extract stock price using regex (looks for ₹ followed by numbers)
|
| 33 |
+
match = re.search(r"₹\s?([\d,]+\.?\d*)", search_results)
|
| 34 |
+
|
| 35 |
if match:
|
| 36 |
+
price = match.group(1) # Extract only the price value
|
| 37 |
+
return f"The current stock price of {company} is ₹{price}."
|
| 38 |
else:
|
| 39 |
return f"Could not find the stock price for {company}. Please check manually."
|
| 40 |
|