Spaces:
Sleeping
Sleeping
Clement Vachet
commited on
Commit
•
98d351c
1
Parent(s):
c2c9c79
Add inference file via API
Browse files- inference_api.py +27 -0
inference_api.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from gradio_client import Client, handle_file
|
2 |
+
from PIL import Image
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
+
|
5 |
+
# Parameters
|
6 |
+
Server_URL = "http://127.0.0.1:7860/"
|
7 |
+
Image_URL = 'http://images.cocodataset.org/val2017/000000039769.jpg'
|
8 |
+
|
9 |
+
# URL to client server (e.g. local server, docker container or AWS ECS)
|
10 |
+
client = Client(Server_URL)
|
11 |
+
|
12 |
+
# Call to API
|
13 |
+
result = client.predict(
|
14 |
+
image=handle_file(Image_URL),
|
15 |
+
api_name="/predict"
|
16 |
+
)
|
17 |
+
|
18 |
+
# Result is an image.webp file
|
19 |
+
print(result)
|
20 |
+
|
21 |
+
# Display image via matplotlib
|
22 |
+
img = Image.open(result).convert("RGB")
|
23 |
+
|
24 |
+
plt.figure(figsize=(8, 5))
|
25 |
+
plt.imshow(img)
|
26 |
+
plt.axis('off')
|
27 |
+
plt.show()
|