|
import gradio as gr |
|
import tensorflow as tf |
|
import gdown |
|
from PIL import Image |
|
|
|
import requests |
|
|
|
API_URL = "https://api-inference.huggingface.co/models/facebook/detr-resnet-50-panoptic" |
|
headers = {"Authorization": "Bearer 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"} |
|
|
|
|
|
|
|
output = query("cats.jpg") |
|
|
|
|
|
|
|
def query(inputs): |
|
with open(inputs, "rb") as f: |
|
data = f.read() |
|
response = requests.post(API_URL, headers=headers, data=data) |
|
return response.json() |
|
|
|
|
|
inputs = gr.inputs.Image(type="pil", label="Upload an image") |
|
|
|
|
|
|
|
title = "<h1 style='text-align: center;'>Image Segmentation</h1>" |
|
description = "Upload an image and get the segmentation result." |
|
|
|
gr.Interface(fn=classify_image, |
|
inputs=inputs, |
|
outputs=query(inputs), |
|
title=title, |
|
examples=[["00_plane.jpg"], ["01_car.jpg"], ["02_bird.jpg"], ["03_cat.jpg"], ["04_deer.jpg"]], |
|
description=description, |
|
enable_queue=True).launch() |