File size: 987 Bytes
dadd386
c5e676e
dadd386
c5e676e
afa2cab
c5e676e
afa2cab
c5e676e
 
dadd386
 
 
c5e676e
 
 
 
 
dadd386
 
 
c5e676e
 
dadd386
 
 
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
import gradio as gr
from transformers import AutoModelForImageClassification, AutoImageProcessor, pipeline

# Carregar o modelo e o processador de imagens
model = AutoModelForImageClassification.from_pretrained("mestrevh/computer-vision-beans", use_safetensors=True)
image_processor = AutoImageProcessor.from_pretrained("mestrevh/computer-vision-beans")

# Criar o pipeline
classifier = pipeline("image-classification", model=model, feature_extractor=image_processor)

# Função de classificação
def predict_image(image):
    # A saída do classifier é uma lista de dicionários, pegar o label e a confiança
    result = classifier(image)
    label = result[0]['label']
    confidence = result[0]['score']
    return f"Class: {label}, Confidence: {confidence:.2f}"

# Interface Gradio
interface = gr.Interface(fn=predict_image, 
                         inputs=gr.Image(type="pil"), 
                         outputs="text", 
                         live=True)

interface.launch()