Spaces:
Sleeping
Sleeping
piotrkan
commited on
Commit
·
c6459bd
1
Parent(s):
3635af0
update
Browse files
app.py
CHANGED
|
@@ -1,5 +1,8 @@
|
|
| 1 |
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
| 2 |
import datetime
|
|
|
|
|
|
|
|
|
|
| 3 |
import requests
|
| 4 |
import pytz
|
| 5 |
import yaml
|
|
@@ -9,14 +12,23 @@ 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 |
-
|
| 14 |
-
"""A tool that does nothing yet
|
| 15 |
Args:
|
| 16 |
arg1: the first argument
|
| 17 |
arg2: the second argument
|
|
|
|
|
|
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -55,7 +67,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 1 |
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
| 2 |
import datetime
|
| 3 |
+
import re
|
| 4 |
+
import json
|
| 5 |
+
from urllib.request import urlopen
|
| 6 |
import requests
|
| 7 |
import pytz
|
| 8 |
import yaml
|
|
|
|
| 12 |
|
| 13 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 14 |
@tool
|
| 15 |
+
def get_ip_address()-> dict: #it's import to specify the return type
|
| 16 |
+
"""A tool which cheks the ip address of the user and returns a string containing IP, Othat does nothing yet
|
|
|
|
| 17 |
Args:
|
| 18 |
arg1: the first argument
|
| 19 |
arg2: the second argument
|
| 20 |
+
Returns:
|
| 21 |
+
A dictionary containing the IP address, city, country, region, and timezone region of the user.
|
| 22 |
"""
|
| 23 |
+
url = "http://ipinfo.io/json"
|
| 24 |
+
response = urlopen(url)
|
| 25 |
+
data = json.load(response)
|
| 26 |
+
IP=data['ip']
|
| 27 |
+
city = data['city']
|
| 28 |
+
country=data['country']
|
| 29 |
+
region=data['region']
|
| 30 |
+
timezone=data['timezone']
|
| 31 |
+
return {"IP": IP, "City": city, "Country": country, "Region": region, "Timezone": timezone}
|
| 32 |
|
| 33 |
@tool
|
| 34 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 67 |
|
| 68 |
agent = CodeAgent(
|
| 69 |
model=model,
|
| 70 |
+
tools=[final_answer, get_current_time_in_timezone, image_generation_tool, get_ip_address], ## add your tools here (don't remove final answer)
|
| 71 |
max_steps=6,
|
| 72 |
verbosity_level=1,
|
| 73 |
grammar=None,
|