Spaces:
Running
Running
modified the app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,25 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import AutoModelForImageClassification,
|
3 |
|
|
|
4 |
model = AutoModelForImageClassification.from_pretrained("mestrevh/computer-vision-beans", use_safetensors=True)
|
5 |
-
|
6 |
|
7 |
-
|
|
|
8 |
|
9 |
# Função de classificação
|
10 |
def predict_image(image):
|
11 |
-
|
|
|
|
|
|
|
|
|
12 |
|
13 |
# Interface Gradio
|
14 |
interface = gr.Interface(fn=predict_image,
|
15 |
-
|
16 |
-
outputs="
|
17 |
live=True)
|
18 |
|
19 |
interface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoModelForImageClassification, AutoImageProcessor, pipeline
|
3 |
|
4 |
+
# Carregar o modelo e o processador de imagens
|
5 |
model = AutoModelForImageClassification.from_pretrained("mestrevh/computer-vision-beans", use_safetensors=True)
|
6 |
+
image_processor = AutoImageProcessor.from_pretrained("mestrevh/computer-vision-beans")
|
7 |
|
8 |
+
# Criar o pipeline
|
9 |
+
classifier = pipeline("image-classification", model=model, feature_extractor=image_processor)
|
10 |
|
11 |
# Função de classificação
|
12 |
def predict_image(image):
|
13 |
+
# A saída do classifier é uma lista de dicionários, pegar o label e a confiança
|
14 |
+
result = classifier(image)
|
15 |
+
label = result[0]['label']
|
16 |
+
confidence = result[0]['score']
|
17 |
+
return f"Class: {label}, Confidence: {confidence:.2f}"
|
18 |
|
19 |
# Interface Gradio
|
20 |
interface = gr.Interface(fn=predict_image,
|
21 |
+
inputs=gr.Image(type="pil"),
|
22 |
+
outputs="text",
|
23 |
live=True)
|
24 |
|
25 |
interface.launch()
|