Update app.py
Browse files
app.py
CHANGED
@@ -1,30 +1,26 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import
|
|
|
3 |
|
4 |
-
#
|
5 |
-
|
|
|
|
|
|
|
|
|
6 |
|
7 |
-
#
|
8 |
def classify_image(img):
|
9 |
-
|
10 |
-
|
11 |
-
label = result[0]['label']
|
12 |
-
probability = result[0]['score']
|
13 |
-
|
14 |
-
# Formate o resultado para exibição
|
15 |
-
output_text = f"Classe: {label}, Probabilidade: {probability:.2f}"
|
16 |
-
|
17 |
-
return output_text
|
18 |
|
19 |
-
# Interface Gradio
|
20 |
iface = gr.Interface(
|
21 |
fn=classify_image,
|
22 |
-
inputs=gr.inputs.Image(),
|
23 |
-
outputs=
|
24 |
-
|
25 |
-
|
26 |
-
description="Carregue uma imagem para classificação.",
|
27 |
)
|
28 |
|
29 |
-
|
30 |
-
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import ViTFeatureExtractor, ViTForImageClassification
|
3 |
+
from hugsvision.inference.VisionClassifierInference import VisionClassifierInference
|
4 |
|
5 |
+
# Load the pre-trained ViT model
|
6 |
+
path = "mrm8488/vit-base-patch16-224_finetuned-kvasirv2-colonoscopy"
|
7 |
+
classifier = VisionClassifierInference(
|
8 |
+
feature_extractor=ViTFeatureExtractor.from_pretrained(path),
|
9 |
+
model=ViTForImageClassification.from_pretrained(path),
|
10 |
+
)
|
11 |
|
12 |
+
# Define a Gradio interface
|
13 |
def classify_image(img):
|
14 |
+
label = classifier.predict(img_path=img)
|
15 |
+
return f"Predicted class: {label}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
|
|
17 |
iface = gr.Interface(
|
18 |
fn=classify_image,
|
19 |
+
inputs=gr.inputs.Image(type="file", label="Upload an image"),
|
20 |
+
outputs="text",
|
21 |
+
title="Image Classifier",
|
22 |
+
description="Classify images using a pre-trained ViT model",
|
|
|
23 |
)
|
24 |
|
25 |
+
# Launch the Gradio app
|
26 |
+
iface.launch()
|