Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,53 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
|
|
|
|
|
|
3 |
|
4 |
-
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
# Definir la interfaz de Gradio
|
8 |
interface = gr.Interface(
|
9 |
-
fn=
|
10 |
-
inputs=gr.
|
11 |
-
|
12 |
-
outputs=gr.Textbox(label="Saludo: "),
|
13 |
title="Blindness Classification",
|
14 |
description="Classify the severity of blindness from retinal images."
|
15 |
)
|
16 |
|
17 |
|
18 |
# Ejecutar la aplicaci贸n
|
19 |
-
interface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from huggingface_hub import hf_hub_download
|
4 |
+
from torchvision import transforms
|
5 |
+
from PIL import Image
|
6 |
+
import requests
|
7 |
+
import os
|
8 |
|
9 |
+
# URL del modelo en Hugging Face
|
10 |
+
model_url = "https://huggingface.co/macapa/blindness_clas/resolve/main/blindness_model.pth"
|
11 |
+
model_path = "best_model_resnet18.pth"
|
12 |
|
13 |
+
|
14 |
+
hf_hub_download(
|
15 |
+
repo_id='macapa/blindness_clas',
|
16 |
+
filename='best_model_resnet18.pth',
|
17 |
+
local_dir='.'
|
18 |
+
)
|
19 |
+
|
20 |
+
|
21 |
+
# Cargar el modelo PyTorch
|
22 |
+
model = torch.load(model_path, map_location=torch.device('cpu'))
|
23 |
+
# model.eval()
|
24 |
+
|
25 |
+
# Definir las transformaciones de la imagen
|
26 |
+
preprocess = transforms.Compose([
|
27 |
+
transforms.Resize((256, 256)),
|
28 |
+
transforms.ToTensor(),
|
29 |
+
])
|
30 |
+
|
31 |
+
# Definir las etiquetas de clasificaci贸n
|
32 |
+
labels = ["No Blindness", "Mild", "Moderate", "Severe", "Proliferative"]
|
33 |
+
|
34 |
+
# Funci贸n para predecir la clase de ceguera
|
35 |
+
def classify_image(img):
|
36 |
+
img = preprocess(img).unsqueeze(0)
|
37 |
+
with torch.no_grad():
|
38 |
+
outputs = model(img)
|
39 |
+
_, predicted = torch.max(outputs, 1)
|
40 |
+
return labels[predicted.item()]
|
41 |
|
42 |
# Definir la interfaz de Gradio
|
43 |
interface = gr.Interface(
|
44 |
+
fn=classify_image,
|
45 |
+
inputs=gr.Image(label="Carga una imagen aqu铆"),
|
46 |
+
outputs=gr.Label(num_top_classes=1),
|
|
|
47 |
title="Blindness Classification",
|
48 |
description="Classify the severity of blindness from retinal images."
|
49 |
)
|
50 |
|
51 |
|
52 |
# Ejecutar la aplicaci贸n
|
53 |
+
interface.launch()
|