AdrianRevi commited on
Commit
440b4dc
·
verified ·
1 Parent(s): bbd316d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -9
app.py CHANGED
@@ -1,17 +1,13 @@
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():
12
- outputs = model(**inputs)
13
- probs = torch.nn.functional.softmax(outputs.logits, dim=1)[0]
14
- labels = model.config.id2label
15
  return {labels[i]: float(probs[i]) for i in range(len(labels))}
16
 
17
  demo = gr.Interface(
 
1
  import gradio as gr
2
+ from fastai.vision.all import *
3
  from PIL import Image
 
 
4
 
5
+ # Cargar modelo exportado desde Hugging Face
6
+ learn = load_learner("https://huggingface.co/AdrianRevi/Practica1Blindness/model.pkl")
7
 
8
  def predict(img: Image.Image):
9
+ pred_class, pred_idx, probs = learn.predict(img)
10
+ labels = learn.dls.vocab
 
 
 
11
  return {labels[i]: float(probs[i]) for i in range(len(labels))}
12
 
13
  demo = gr.Interface(