Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from fastai.vision.all import load_learner, PILImage
|
| 3 |
+
from huggingface_hub import hf_hub_download
|
| 4 |
+
|
| 5 |
+
MODEL_REPO = "Clau31/aptos-practica1"
|
| 6 |
+
MODEL_FILE = "model.pkl" # si tu repo tiene otro nombre, cámbialo aquí
|
| 7 |
+
|
| 8 |
+
model_path = hf_hub_download(repo_id=MODEL_REPO, filename=MODEL_FILE)
|
| 9 |
+
learn = load_learner(model_path)
|
| 10 |
+
|
| 11 |
+
def predict(img):
|
| 12 |
+
img = PILImage.create(img)
|
| 13 |
+
pred, pred_idx, probs = learn.predict(img)
|
| 14 |
+
return {str(i): float(probs[i]) for i in range(len(probs))}
|
| 15 |
+
|
| 16 |
+
app = gr.Interface(
|
| 17 |
+
fn=predict,
|
| 18 |
+
inputs=gr.Image(type="pil"),
|
| 19 |
+
outputs=gr.Label(num_top_classes=5),
|
| 20 |
+
title="APTOS 2019 – Detección de Ceguera",
|
| 21 |
+
description="Sube una imagen de retina y el modelo predice la clase (0–4)."
|
| 22 |
+
)
|