Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,11 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from PIL import Image
|
| 3 |
import torch
|
| 4 |
-
from torchvision import transforms
|
| 5 |
from transformers import AutoModelForImageClassification, AutoFeatureExtractor
|
| 6 |
|
| 7 |
-
# Cargar el modelo desde Hugging Face Hub
|
| 8 |
model = AutoModelForImageClassification.from_pretrained("AdrianRevi/Practica1Blindness")
|
| 9 |
extractor = AutoFeatureExtractor.from_pretrained("AdrianRevi/Practica1Blindness")
|
| 10 |
|
| 11 |
-
# Preprocesamiento
|
| 12 |
def predict(img: Image.Image):
|
| 13 |
inputs = extractor(images=img, return_tensors="pt")
|
| 14 |
with torch.no_grad():
|
|
@@ -17,12 +14,11 @@ def predict(img: Image.Image):
|
|
| 17 |
labels = model.config.id2label
|
| 18 |
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
| 19 |
|
| 20 |
-
# Interfaz Gradio
|
| 21 |
demo = gr.Interface(
|
| 22 |
fn=predict,
|
| 23 |
inputs=gr.Image(type="pil"),
|
| 24 |
outputs=gr.Label(num_top_classes=3),
|
| 25 |
-
examples=["20068.jpg", "20084.jpg"],
|
| 26 |
title="Blindness Detection",
|
| 27 |
description="Sube una imagen del ojo para detectar el grado de ceguera.",
|
| 28 |
)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from PIL import Image
|
| 3 |
import torch
|
|
|
|
| 4 |
from transformers import AutoModelForImageClassification, AutoFeatureExtractor
|
| 5 |
|
|
|
|
| 6 |
model = AutoModelForImageClassification.from_pretrained("AdrianRevi/Practica1Blindness")
|
| 7 |
extractor = AutoFeatureExtractor.from_pretrained("AdrianRevi/Practica1Blindness")
|
| 8 |
|
|
|
|
| 9 |
def predict(img: Image.Image):
|
| 10 |
inputs = extractor(images=img, return_tensors="pt")
|
| 11 |
with torch.no_grad():
|
|
|
|
| 14 |
labels = model.config.id2label
|
| 15 |
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
| 16 |
|
|
|
|
| 17 |
demo = gr.Interface(
|
| 18 |
fn=predict,
|
| 19 |
inputs=gr.Image(type="pil"),
|
| 20 |
outputs=gr.Label(num_top_classes=3),
|
| 21 |
+
examples=["examples/20068.jpg", "examples/20084.jpg"],
|
| 22 |
title="Blindness Detection",
|
| 23 |
description="Sube una imagen del ojo para detectar el grado de ceguera.",
|
| 24 |
)
|