Spaces:
Sleeping
Sleeping
added live crypto price predictor
Browse files
app.py
CHANGED
|
@@ -9,14 +9,25 @@ 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
|
| 13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
-
"""A tool that
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
arg2: the second argument
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -55,7 +66,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer, get_current_time_in_timezone], ## add your tools here (don't remove final answer)
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
+
def live_crypto_price(cryptocurrencies:list)-> str: #it's import to specify the return type
|
| 13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
+
"""A tool that gets the live crypto currency prices of specified crypto currencies.
|
| 15 |
Args:
|
| 16 |
+
cryptocurrencies: list containing the cryptocurrencies of which prices are required (e.g., ['bitcoin', 'cardano'])
|
|
|
|
| 17 |
"""
|
| 18 |
+
results = []
|
| 19 |
+
try:
|
| 20 |
+
url = "https://api.coingecko.com/api/v3/simple/price"
|
| 21 |
+
cryptos = ','.join(c for c in cryptocurrencies)
|
| 22 |
+
parms = {ids: cryptos,
|
| 23 |
+
vs_currencies: "inr"}
|
| 24 |
+
response = requests.get(url, params=params)
|
| 25 |
+
data = response.json()
|
| 26 |
+
for keys, values in data.items():
|
| 27 |
+
results.append(f"the price of {keys} is {values['inr']}.")
|
| 28 |
+
return ''.join(result for result in results)
|
| 29 |
+
except:
|
| 30 |
+
return f"Error fetching prices for {cryptos}."
|
| 31 |
|
| 32 |
@tool
|
| 33 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 66 |
|
| 67 |
agent = CodeAgent(
|
| 68 |
model=model,
|
| 69 |
+
tools=[final_answer, get_current_time_in_timezone, live_crypto_price], ## add your tools here (don't remove final answer)
|
| 70 |
max_steps=6,
|
| 71 |
verbosity_level=1,
|
| 72 |
grammar=None,
|