Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from huggingface_hub import from_pretrained_fastai
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from fastai.vision.all import *
|
| 4 |
+
|
| 5 |
+
repo_id = "paascorb/image-detection-efficientdet"
|
| 6 |
+
|
| 7 |
+
learner = from_pretrained_fastai(repo_id)
|
| 8 |
+
labels = learner.dls.vocab
|
| 9 |
+
|
| 10 |
+
# Definimos una función que se encarga de llevar a cabo las predicciones
|
| 11 |
+
def predict(img):
|
| 12 |
+
img = PIL.Image.open('mapaches/test/images/raccoon-190.jpg')
|
| 13 |
+
infer_tfms = tfms.A.Adapter([*tfms.A.resize_and_pad(size),tfms.A.Normalize()])
|
| 14 |
+
pred_dict = models.ross.efficientdet.end2end_detect(img, infer_tfms, model.to("cpu"), class_map=class_map, detection_threshold=0.5)
|
| 15 |
+
return pred_dict["img"]
|
| 16 |
+
|
| 17 |
+
# Creamos la interfaz y la lanzamos.
|
| 18 |
+
gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(128, 128)), outputs=gr.outputs.Image(shape(128,128)),examples=['buildings.jpg','forest.jpg']).launch(share=False)
|