Commit
·
ffd20c7
1
Parent(s):
e28c3ee
Update app.py
Browse files
app.py
CHANGED
@@ -1,36 +1,12 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import requests
|
3 |
-
from PIL import Image
|
4 |
-
|
5 |
import requests
|
6 |
|
7 |
API_URL = "https://api-inference.huggingface.co/models/facebook/detr-resnet-50-panoptic"
|
8 |
headers = {"Authorization": "Bearer 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"}
|
9 |
-
inputs = gr.inputs.Image(type="pil", label="Upload an image")
|
10 |
-
|
11 |
-
# Perform image segmentation for multy class output
|
12 |
-
# def query(inputs):
|
13 |
-
# response = requests.post(API_URL, headers=headers, data=inputs)
|
14 |
-
# return response.json()
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
with open(inputs, "rb") as f:
|
19 |
data = f.read()
|
20 |
response = requests.post(API_URL, headers=headers, data=data)
|
21 |
return response.json()
|
22 |
|
23 |
-
|
24 |
-
outputs = gr.outputs.HTML()
|
25 |
-
# outputs = gr.outputs.HTML() #uncomment for single class output
|
26 |
-
#outputs = query(inputs)
|
27 |
-
|
28 |
-
title = "<h1 style='text-align: center;'>Image Segmentation</h1>"
|
29 |
-
description = "Upload an image and get the segmentation result."
|
30 |
-
|
31 |
-
gr.Interface(fn=query,
|
32 |
-
inputs=inputs,
|
33 |
-
outputs=outputs,
|
34 |
-
title=title,
|
35 |
-
examples=[["00_plane.jpg"], ["01_car.jpg"], ["02_bird.jpg"], ["03_cat.jpg"], ["04_deer.jpg"]],
|
36 |
-
description=description).launch()
|
|
|
|
|
|
|
|
|
|
|
1 |
import requests
|
2 |
|
3 |
API_URL = "https://api-inference.huggingface.co/models/facebook/detr-resnet-50-panoptic"
|
4 |
headers = {"Authorization": "Bearer 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"}
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
+
def query(filename):
|
7 |
+
with open(filename, "rb") as f:
|
|
|
8 |
data = f.read()
|
9 |
response = requests.post(API_URL, headers=headers, data=data)
|
10 |
return response.json()
|
11 |
|
12 |
+
output = query("cats.jpg")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|