Clau31 commited on
Commit
545f2b4
·
verified ·
1 Parent(s): eba7913

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -2,21 +2,29 @@ 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
- )
 
 
 
 
 
2
  from fastai.vision.all import load_learner, PILImage
3
  from huggingface_hub import hf_hub_download
4
 
5
+ # Repo del modelo
6
  MODEL_REPO = "Clau31/aptos-practica1"
7
+ MODEL_FILE = "model.pkl"
8
 
9
+ # Descargar y cargar el modelo
10
  model_path = hf_hub_download(repo_id=MODEL_REPO, filename=MODEL_FILE)
11
  learn = load_learner(model_path)
12
 
13
+ # Función de predicción
14
  def predict(img):
15
  img = PILImage.create(img)
16
  pred, pred_idx, probs = learn.predict(img)
17
  return {str(i): float(probs[i]) for i in range(len(probs))}
18
 
19
+ # Interfaz Gradio
20
+ demo = gr.Interface(
21
  fn=predict,
22
  inputs=gr.Image(type="pil"),
23
  outputs=gr.Label(num_top_classes=5),
24
  title="APTOS 2019 – Detección de Ceguera",
25
+ description="Modelo de clasificación entrenado con FastAI"
26
+ )
27
+
28
+ if __name__ == "__main__":
29
+ demo.queue()
30
+ demo.launch()