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