roderikout commited on
Commit
66543b2
1 Parent(s): 1a98637

Primer Commit

Browse files

Subiendo primer archivo app.py y modelo

Files changed (2) hide show
  1. PapaRod.pkl +3 -0
  2. app.py +51 -0
PapaRod.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e5f97789ce4ce1ede5e760f997e3dcbdf533e33b9bc21f49c687c37fafaeb2ee
3
+ size 46964897
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # AUTOGENERATED! DO NOT EDIT! File to edit: Todo_para_ml_imagenes.ipynb.
2
+
3
+ # %% auto 0
4
+ __all__ = ['path', 'learn_inf', 'btn_upload', 'out_pl', 'lbl_pred', 'btn_run', 'labels', 'demo', 'on_click_classify', 'predict']
5
+
6
+ # %% Todo_para_ml_imagenes.ipynb 4
7
+ from pathlib import Path
8
+ from fastcore.all import *
9
+ from fastai.vision.all import *
10
+ from fastai.vision.widgets import *
11
+
12
+ # %% Todo_para_ml_imagenes.ipynb 28
13
+ path = Path()
14
+ path.ls(file_exts='.pkl')
15
+
16
+ # %% Todo_para_ml_imagenes.ipynb 30
17
+ learn_inf = load_learner(path/'PapaRod.pkl')
18
+
19
+ # %% Todo_para_ml_imagenes.ipynb 43
20
+ btn_upload = widgets.FileUpload()
21
+ out_pl = widgets.Output()
22
+ lbl_pred = widgets.Label()
23
+ btn_run = widgets.Button(description='Classify')
24
+
25
+ # %% Todo_para_ml_imagenes.ipynb 44
26
+ def on_click_classify(change):
27
+ img = PILImage.create(btn_upload.data[-1])
28
+ out_pl.clear_output()
29
+ with out_pl: display(img.to_thumb(128,128))
30
+ pred,pred_idx,probs = learn_inf.predict(img)
31
+ lbl_pred.value = f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}'
32
+
33
+ btn_run.on_click(on_click_classify)
34
+
35
+ # %% Todo_para_ml_imagenes.ipynb 54
36
+ import gradio as gr
37
+
38
+ labels = learn_inf.dls.vocab
39
+ def predict(img):
40
+ img = PILImage.create(img)
41
+ pred,pred_idx,probs = learn_inf.predict(img)
42
+ return {labels[i]: float(probs[i]) for i in range(len(labels))}
43
+
44
+ # %% Todo_para_ml_imagenes.ipynb 56
45
+ demo = gr.Interface(
46
+ predict,
47
+ gr.Image(source="webcam", streaming=False),
48
+ outputs=gr.components.Label(num_top_classes=3),
49
+ interpretation='default',
50
+ live=True
51
+ ).launch(share=True)