Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,12 +23,12 @@ from Gradio_UI import GradioUI
|
|
| 23 |
|
| 24 |
@tool
|
| 25 |
def get_stock_information(stock:str) -> str:
|
| 26 |
-
|
| 27 |
Args:
|
| 28 |
stock: A string representing a valid str (e.g., 'googl').
|
| 29 |
Returns:
|
| 30 |
str
|
| 31 |
-
|
| 32 |
try:
|
| 33 |
data=yf.Ticker(stock)
|
| 34 |
info1=data.info
|
|
@@ -36,34 +36,31 @@ def get_stock_information(stock:str) -> str:
|
|
| 36 |
except Exception as e:
|
| 37 |
return f"Error fetching stock info '{stock}': {str(e)}"
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
# res = conn.getresponse()
|
| 58 |
-
# dt = json.loads(res.read().decode("utf-8"))
|
| 59 |
-
#
|
| 60 |
-
# return [
|
| 61 |
-
# station["streams"][0]["url"]
|
| 62 |
-
# for station in dt.get("data", [])
|
| 63 |
-
# if station.get("streams")
|
| 64 |
-
# ]
|
| 65 |
-
# except Exception as e:
|
| 66 |
-
# return [f"Error: {str(e)}"]
|
| 67 |
|
| 68 |
@tool
|
| 69 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -102,7 +99,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 102 |
|
| 103 |
agent = CodeAgent(
|
| 104 |
model=model,
|
| 105 |
-
tools=[final_answer,get_current_time_in_timezone,get_stock_information], ## add your tools here (don't remove final answer)
|
| 106 |
max_steps=6,
|
| 107 |
verbosity_level=1,
|
| 108 |
grammar=None,
|
|
|
|
| 23 |
|
| 24 |
@tool
|
| 25 |
def get_stock_information(stock:str) -> str:
|
| 26 |
+
""" this tool provide company information for the input stock ticker
|
| 27 |
Args:
|
| 28 |
stock: A string representing a valid str (e.g., 'googl').
|
| 29 |
Returns:
|
| 30 |
str
|
| 31 |
+
"""
|
| 32 |
try:
|
| 33 |
data=yf.Ticker(stock)
|
| 34 |
info1=data.info
|
|
|
|
| 36 |
except Exception as e:
|
| 37 |
return f"Error fetching stock info '{stock}': {str(e)}"
|
| 38 |
|
| 39 |
+
@tool
|
| 40 |
+
def get_radio_station(input_cr : str) -> list:
|
| 41 |
+
""" this function fetches streams to radio stations for input_cr, it print str urls addresses
|
| 42 |
+
Args:
|
| 43 |
+
input_cr (str) :A string representing a valid input_cr (e.g., 'us')
|
| 44 |
+
"""
|
| 45 |
+
try:
|
| 46 |
+
conn = http.client.HTTPSConnection("50k-radio-stations.p.rapidapi.com")
|
| 47 |
+
|
| 48 |
+
headers = {
|
| 49 |
+
"x-rapidapi-key": "edb18a5d52msh741fb6d677c3be2p1c3c92jsn41ac9a131361",
|
| 50 |
+
"x-rapidapi-host": "50k-radio-stations.p.rapidapi.com",
|
| 51 |
+
}
|
| 52 |
|
| 53 |
+
conn.request("GET", f"/radios/popular/{input_cr}?limit=6", headers=headers)
|
| 54 |
+
res = conn.getresponse()
|
| 55 |
+
dt = json.loads(res.read().decode("utf-8"))
|
| 56 |
+
|
| 57 |
+
return [
|
| 58 |
+
station["streams"][0]["url"]
|
| 59 |
+
for station in dt.get("data", [])
|
| 60 |
+
if station.get("streams")
|
| 61 |
+
]
|
| 62 |
+
except Exception as e:
|
| 63 |
+
return [f"Error: {str(e)}"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
@tool
|
| 66 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 99 |
|
| 100 |
agent = CodeAgent(
|
| 101 |
model=model,
|
| 102 |
+
tools=[final_answer,get_current_time_in_timezone,get_stock_information,get_radio_station], ## add your tools here (don't remove final answer)
|
| 103 |
max_steps=6,
|
| 104 |
verbosity_level=1,
|
| 105 |
grammar=None,
|