prige commited on
Commit
c0163a7
·
verified ·
1 Parent(s): a6949d7

Upload tool

Browse files
Files changed (3) hide show
  1. app.py +6 -0
  2. requirements.txt +2 -0
  3. tool.py +24 -0
app.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ from smolagents import launch_gradio_demo
2
+ from tool import UserLocationTool
3
+
4
+ tool = UserLocationTool()
5
+
6
+ launch_gradio_demo(tool)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ smolagents
2
+ requests
tool.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Any, Optional
2
+ from smolagents.tools import Tool
3
+ import requests
4
+
5
+ class UserLocationTool(Tool):
6
+ name = "get_user_location"
7
+ description = "This tool returns the user's location based on their IP address. That is all it does."
8
+ inputs = {}
9
+ output_type = "string"
10
+
11
+ def __init__(self):
12
+ super().__init__()
13
+ self.dependencies = ["requests"]
14
+
15
+ def forward(self) -> str:
16
+ # Import requests inside the function as per requirements
17
+ import requests
18
+
19
+ try:
20
+ response = requests.get("https://ipinfo.io/")
21
+ data = response.json()
22
+ return data["city"]
23
+ except Exception as e:
24
+ return f"Error getting user location: {str(e)}. It looks like https://ipinfo.io/ did not return a valid response."