Spaces:
Runtime error
Runtime error
HangenYuu
commited on
Commit
·
e351916
1
Parent(s):
cb60d26
Updated app.py
Browse files- Screenshot 2023-05-05 085533.png +0 -0
- app.py +39 -3
Screenshot 2023-05-05 085533.png
ADDED
![]() |
app.py
CHANGED
@@ -1,7 +1,43 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
return "Hello " + name + "!!"
|
5 |
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import requests
|
3 |
+
from PIL import Image
|
4 |
+
from io import BytesIO
|
5 |
|
6 |
+
url = 'http://146.190.200.87:8000/predict'
|
|
|
7 |
|
8 |
+
def inference(input_image):
|
9 |
+
# Convert the PIL image to bytes
|
10 |
+
img_bytes = BytesIO()
|
11 |
+
input_image.save(img_bytes, format='JPEG')
|
12 |
+
|
13 |
+
# Send the POST request with the image data as 'image' key
|
14 |
+
files = {'image': ('input.jpg', img_bytes.getvalue(), 'image/jpeg')}
|
15 |
+
response = requests.post(url, files=files)
|
16 |
+
|
17 |
+
# Check if the request was successful (status code 200)
|
18 |
+
if response.status_code == 200:
|
19 |
+
# Assuming the response is in JSON format, extract the category and probability information
|
20 |
+
result = response.json()
|
21 |
+
# Assuming the response contains category: probability pairs
|
22 |
+
# Sort the results by probability in descending order and take the top 5
|
23 |
+
sorted_results = sorted(result.items(), key=lambda x: x[1], reverse=True)[:5]
|
24 |
+
return sorted_results
|
25 |
+
else:
|
26 |
+
print("POST request failed with status code:", response.status_code)
|
27 |
+
return None
|
28 |
+
|
29 |
+
title = "SeeFood102"
|
30 |
+
description = "Gradio frontend for SeeFood102, the expansion edition of SeeFood101."
|
31 |
+
|
32 |
+
examples = [
|
33 |
+
[Image.open('Screenshot 2023-05-05 085533.png')]
|
34 |
+
]
|
35 |
+
|
36 |
+
iface = gr.Interface(fn=inference,
|
37 |
+
inputs=gr.Image(type="pil"),
|
38 |
+
outputs=gr.Label(num_top_classes=5),
|
39 |
+
title=title,
|
40 |
+
description=description,
|
41 |
+
examples=examples,
|
42 |
+
analytics_enabled=False)
|
43 |
iface.launch()
|