added API doc
Browse files- app.py +15 -2
- client.py +8 -0
- test_rest.py +9 -0
app.py
CHANGED
@@ -27,8 +27,21 @@ gradio_interface = gr.Interface(
|
|
27 |
outputs="text",
|
28 |
title="REST API with Gradio and Huggingface Spaces",
|
29 |
description='''Inputs should be json of test item e.g., as a dictionary;
|
30 |
-
output right now is just returning the input; later label will be returned
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
gradio_interface.launch()
|
33 |
# anvil.server.wait_forever()
|
34 |
|
|
|
27 |
outputs="text",
|
28 |
title="REST API with Gradio and Huggingface Spaces",
|
29 |
description='''Inputs should be json of test item e.g., as a dictionary;
|
30 |
+
output right now is just returning the input; later label will be returned.
|
31 |
+
|
32 |
+
This is how to call the API from Python:
|
33 |
+
|
34 |
+
import requests
|
35 |
+
|
36 |
+
response = requests.post("https://gmshroff-gmserver.hf.space/run/predict", json={
|
37 |
+
"data": [
|
38 |
+
"<some json string>",
|
39 |
+
]}).json()
|
40 |
+
|
41 |
+
data = response["data"])
|
42 |
+
|
43 |
+
''')
|
44 |
+
|
45 |
gradio_interface.launch()
|
46 |
# anvil.server.wait_forever()
|
47 |
|
client.py
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from gradio_client import Client
|
2 |
+
|
3 |
+
client = Client("https://gmshroff-gmserver.hf.space/")
|
4 |
+
result = client.predict(
|
5 |
+
"{'name':'Gautam'}", # str in 'name' Textbox component
|
6 |
+
api_name="/predict"
|
7 |
+
)
|
8 |
+
print(result)
|
test_rest.py
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
|
3 |
+
response = requests.post("https://gmshroff-gmserver.hf.space/run/predict", json={
|
4 |
+
"data": [
|
5 |
+
"<some json string>",
|
6 |
+
]}).json()
|
7 |
+
|
8 |
+
data = response["data"]
|
9 |
+
print(data)
|