|
from transformers import ViTFeatureExtractor, ViTForImageClassification |
|
from hugsvision.inference.VisionClassifierInference import VisionClassifierInference |
|
import gradio as gr |
|
import cv2 |
|
import numpy as np |
|
|
|
|
|
path = "mrm8488/vit-base-patch16-224_finetuned-kvasirv2-colonoscopy" |
|
feature_extractor = ViTFeatureExtractor.from_pretrained(path) |
|
model = ViTForImageClassification.from_pretrained(path) |
|
|
|
|
|
classifier = VisionClassifierInference( |
|
feature_extractor=feature_extractor, |
|
model=model, |
|
) |
|
|
|
|
|
def classify_image_with_overlay(img): |
|
|
|
img_pil = Image.fromarray(img) |
|
|
|
|
|
image_with_text = classificar_imagem(img_pil) |
|
|
|
|
|
image_with_text_np = np.array(image_with_text) |
|
|
|
return image_with_text_np |
|
|
|
iface = gr.Interface( |
|
fn=classify_image_with_overlay, |
|
inputs=gr.inputs.Image(), |
|
outputs=gr.outputs.Image(type="numpy"), |
|
live=True, |
|
title="ViT Image Classifier with Overlay", |
|
description="Upload an image for classification with label overlay.", |
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
iface.launch() |
|
|