|
import gradio as gr |
|
from PIL import Image |
|
from transformers import AutoFeatureExtractor, AutoModelForImageSegmentation |
|
import tensorflow as tf |
|
|
|
extractor = AutoFeatureExtractor.from_pretrained("facebook/detr-resnet-50-panoptic") |
|
model = AutoModelForImageSegmentation.from_pretrained("facebook/detr-resnet-50-panoptic") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def predict_class(image): |
|
img = tf.cast(image, tf.float32) |
|
prediction = model.predict(img) |
|
return prediction |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def classify_image(image): |
|
results = predict_class(image) |
|
|
|
return results |
|
|
|
|
|
inputs = gr.inputs.Image(type="pil", label="Upload an image") |
|
|
|
outputs = gr.outputs.Label(num_top_classes=4) |
|
|
|
title = "<h1 style='text-align: center;'>Image Classifier</h1>" |
|
description = "Upload an image and get the predicted class." |
|
|
|
|
|
gr.Interface(fn=classify_image, |
|
inputs=inputs, |
|
outputs=outputs, |
|
title=title, |
|
examples=[["00_plane.jpg"], ["01_car.jpg"], ["02_bird.jpg"], ["03_cat.jpg"], ["04_deer.jpg"]], |
|
|
|
description=description).launch() |