Spaces:
Sleeping
Sleeping
Commit
•
e7ba287
1
Parent(s):
40ebef9
Usando Blocks
Browse filesAhora usando blocks para llamar a gradio y poder manipular los botones
app.py
CHANGED
@@ -1,26 +1,22 @@
|
|
1 |
# AUTOGENERATED! DO NOT EDIT! File to edit: Todo_para_ml_imagenes.ipynb.
|
2 |
|
3 |
# %% auto 0
|
4 |
-
__all__ = ['plt', 'path', 'learn_inf', 'labels', '
|
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 |
import pathlib
|
13 |
plt = platform.system()
|
14 |
if plt != 'Windows': pathlib.WindowsPath = pathlib.PosixPath
|
15 |
|
16 |
-
# %% Todo_para_ml_imagenes.ipynb
|
17 |
path = Path()
|
18 |
-
#path.ls(file_exts='.pkl')
|
19 |
|
20 |
-
# %% Todo_para_ml_imagenes.ipynb
|
21 |
learn_inf = load_learner(path/'PapaRod.pkl')
|
22 |
|
23 |
-
# %% Todo_para_ml_imagenes.ipynb
|
24 |
import gradio as gr
|
25 |
|
26 |
labels = learn_inf.dls.vocab
|
@@ -29,10 +25,19 @@ def predict(img):
|
|
29 |
pred,pred_idx,probs = learn_inf.predict(img)
|
30 |
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
# AUTOGENERATED! DO NOT EDIT! File to edit: Todo_para_ml_imagenes.ipynb.
|
2 |
|
3 |
# %% auto 0
|
4 |
+
__all__ = ['plt', 'path', 'learn_inf', 'labels', 'predict', 'clear']
|
5 |
|
6 |
# %% Todo_para_ml_imagenes.ipynb 4
|
7 |
from pathlib import Path
|
|
|
8 |
from fastai.vision.all import *
|
|
|
|
|
9 |
import pathlib
|
10 |
plt = platform.system()
|
11 |
if plt != 'Windows': pathlib.WindowsPath = pathlib.PosixPath
|
12 |
|
13 |
+
# %% Todo_para_ml_imagenes.ipynb 29
|
14 |
path = Path()
|
|
|
15 |
|
16 |
+
# %% Todo_para_ml_imagenes.ipynb 31
|
17 |
learn_inf = load_learner(path/'PapaRod.pkl')
|
18 |
|
19 |
+
# %% Todo_para_ml_imagenes.ipynb 55
|
20 |
import gradio as gr
|
21 |
|
22 |
labels = learn_inf.dls.vocab
|
|
|
25 |
pred,pred_idx,probs = learn_inf.predict(img)
|
26 |
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
27 |
|
28 |
+
def clear():
|
29 |
+
return None
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
+
# %% Todo_para_ml_imagenes.ipynb 58
|
34 |
+
with gr.Blocks() as demo:
|
35 |
+
gr.Markdown("## Tómate una foto a ver si te reconoce.")
|
36 |
+
with gr.Row():
|
37 |
+
image_input = gr.Image(source="webcam", streaming=False)
|
38 |
+
output = gr.components.Label(num_top_classes=3)
|
39 |
+
image_button = gr.Button("¿Quién es?")
|
40 |
+
|
41 |
+
image_button.click(predict, inputs=image_input, outputs=output)
|
42 |
+
|
43 |
+
demo.launch()
|