Spaces:
Running
Running
Upload tool
Browse files- app.py +4 -0
- requirements.txt +1 -1
- tool_config.json +1 -1
- wolfram_alpha_tool.py +4 -4
app.py
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import launch_gradio_demo
|
2 |
+
from wolfram_alpha_tool import WolframAlpha
|
3 |
+
|
4 |
+
launch_gradio_demo(WolframAlpha)
|
requirements.txt
CHANGED
@@ -1,2 +1,2 @@
|
|
1 |
-
transformers
|
2 |
requests
|
|
|
|
|
|
1 |
requests
|
2 |
+
transformers
|
tool_config.json
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
{
|
2 |
-
"description": "This is a tool that uses WolframAlpha to compute any mathematical
|
3 |
"name": "wolfram_alpha",
|
4 |
"tool_class": "wolfram_alpha_tool.WolframAlpha"
|
5 |
}
|
|
|
1 |
{
|
2 |
+
"description": "This is a tool that uses WolframAlpha to compute any mathematical query. It takes one input query, and returns a verbose result in xml format, which includes the solution.",
|
3 |
"name": "wolfram_alpha",
|
4 |
"tool_class": "wolfram_alpha_tool.WolframAlpha"
|
5 |
}
|
wolfram_alpha_tool.py
CHANGED
@@ -1,13 +1,15 @@
|
|
1 |
from transformers import Tool
|
|
|
2 |
|
3 |
class WolframAlpha(Tool):
|
4 |
name = "wolfram_alpha"
|
5 |
-
description = ("This is a tool that uses WolframAlpha to compute any mathematical
|
6 |
|
7 |
inputs = ["query"]
|
8 |
outputs = ["result"]
|
9 |
|
10 |
def __call__(self, query, output='xml', pod_format='plaintext'):
|
|
|
11 |
base_url = 'http://api.wolframalpha.com/v2/query'
|
12 |
|
13 |
output_opts = ['xml','json']
|
@@ -24,9 +26,7 @@ class WolframAlpha(Tool):
|
|
24 |
'output': output,
|
25 |
'appid': CFG_appid,
|
26 |
}
|
27 |
-
print("About to response")
|
28 |
response = requests.get(base_url, params=params)
|
29 |
-
print("response:",response)
|
30 |
if response.status_code == 200:
|
31 |
if output == 'xml':
|
32 |
return response.text
|
@@ -34,4 +34,4 @@ class WolframAlpha(Tool):
|
|
34 |
# Remove unnecessary empty spaces
|
35 |
return str(response.json())
|
36 |
else:
|
37 |
-
return f"There was an error with the request, with response: {response}"
|
|
|
1 |
from transformers import Tool
|
2 |
+
import requests
|
3 |
|
4 |
class WolframAlpha(Tool):
|
5 |
name = "wolfram_alpha"
|
6 |
+
description = ("This is a tool that uses WolframAlpha to compute any mathematical query. It takes one input query, and returns a verbose result in xml format, which includes the solution.")
|
7 |
|
8 |
inputs = ["query"]
|
9 |
outputs = ["result"]
|
10 |
|
11 |
def __call__(self, query, output='xml', pod_format='plaintext'):
|
12 |
+
CFG_appid="YOUR_WOLFRAM_API_KEY_HERE"
|
13 |
base_url = 'http://api.wolframalpha.com/v2/query'
|
14 |
|
15 |
output_opts = ['xml','json']
|
|
|
26 |
'output': output,
|
27 |
'appid': CFG_appid,
|
28 |
}
|
|
|
29 |
response = requests.get(base_url, params=params)
|
|
|
30 |
if response.status_code == 200:
|
31 |
if output == 'xml':
|
32 |
return response.text
|
|
|
34 |
# Remove unnecessary empty spaces
|
35 |
return str(response.json())
|
36 |
else:
|
37 |
+
return f"There was an error with the request, with response: {response}"
|