Mati
commited on
Commit
·
07403e8
1
Parent(s):
84efb83
fixed sketchpad
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ from pathlib import Path
|
|
| 2 |
import torch
|
| 3 |
import gradio as gr
|
| 4 |
from torch import nn
|
|
|
|
| 5 |
|
| 6 |
LABELS = Path("class_names.txt").read_text().splitlines()
|
| 7 |
|
|
@@ -20,6 +21,7 @@ model = nn.Sequential(
|
|
| 20 |
nn.ReLU(),
|
| 21 |
nn.Linear(256, len(LABELS)),
|
| 22 |
)
|
|
|
|
| 23 |
state_dict = torch.load("pytorch_model.bin", map_location="cpu")
|
| 24 |
model.load_state_dict(state_dict, strict=False)
|
| 25 |
model.eval()
|
|
@@ -27,17 +29,20 @@ model.eval()
|
|
| 27 |
|
| 28 |
def predict(im):
|
| 29 |
if(im is not None):
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
| 31 |
with torch.no_grad():
|
| 32 |
out = model(x)
|
| 33 |
probabilities = torch.nn.functional.softmax(out[0], dim=0)
|
| 34 |
values, indices = torch.topk(probabilities, 5)
|
| 35 |
return {LABELS[i]: v.item() for i, v in zip(indices, values)}
|
| 36 |
|
| 37 |
-
|
| 38 |
interface = gr.Interface(
|
| 39 |
predict,
|
| 40 |
-
inputs=
|
| 41 |
outputs="label",
|
| 42 |
theme="huggingface",
|
| 43 |
title="Reconocimiento de garabtosss",
|
|
@@ -45,4 +50,4 @@ description="Querés jugar al Picdictonary con una AI? Dibujá un objeto cotidia
|
|
| 45 |
article="<p style='text-align: center'>Reconocimiento de Garabatos | Demo Model</p>",
|
| 46 |
live=True,
|
| 47 |
)
|
| 48 |
-
interface.launch()
|
|
|
|
| 2 |
import torch
|
| 3 |
import gradio as gr
|
| 4 |
from torch import nn
|
| 5 |
+
import cv2
|
| 6 |
|
| 7 |
LABELS = Path("class_names.txt").read_text().splitlines()
|
| 8 |
|
|
|
|
| 21 |
nn.ReLU(),
|
| 22 |
nn.Linear(256, len(LABELS)),
|
| 23 |
)
|
| 24 |
+
|
| 25 |
state_dict = torch.load("pytorch_model.bin", map_location="cpu")
|
| 26 |
model.load_state_dict(state_dict, strict=False)
|
| 27 |
model.eval()
|
|
|
|
| 29 |
|
| 30 |
def predict(im):
|
| 31 |
if(im is not None):
|
| 32 |
+
# print(im.size)
|
| 33 |
+
im = cv2.resize(im, dsize=(28, 28), interpolation=cv2.INTER_CUBIC)
|
| 34 |
+
x = torch.tensor(im, dtype=torch.float32).unsqueeze(0).unsqueeze(0) / 255.0
|
| 35 |
+
# print(type(im), im.size)
|
| 36 |
with torch.no_grad():
|
| 37 |
out = model(x)
|
| 38 |
probabilities = torch.nn.functional.softmax(out[0], dim=0)
|
| 39 |
values, indices = torch.topk(probabilities, 5)
|
| 40 |
return {LABELS[i]: v.item() for i, v in zip(indices, values)}
|
| 41 |
|
| 42 |
+
sp = gr.Sketchpad(shape=(56,56),brush_radius =1)
|
| 43 |
interface = gr.Interface(
|
| 44 |
predict,
|
| 45 |
+
inputs=sp,
|
| 46 |
outputs="label",
|
| 47 |
theme="huggingface",
|
| 48 |
title="Reconocimiento de garabtosss",
|
|
|
|
| 50 |
article="<p style='text-align: center'>Reconocimiento de Garabatos | Demo Model</p>",
|
| 51 |
live=True,
|
| 52 |
)
|
| 53 |
+
interface.launch()
|
hugg
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
-----BEGIN OPENSSH PRIVATE KEY-----
|
| 2 |
+
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
|
| 3 |
+
QyNTUxOQAAACDWyBwj820SKGSnQe8shCizpUiPbMaXH4H9PMdRjK4zlgAAAKBssbVYbLG1
|
| 4 |
+
WAAAAAtzc2gtZWQyNTUxOQAAACDWyBwj820SKGSnQe8shCizpUiPbMaXH4H9PMdRjK4zlg
|
| 5 |
+
AAAEAUxfh4KZ+ntU7ttAHhYLz9Va3gl7UoTLLvYVo/+Mo49tbIHCPzbRIoZKdB7yyEKLOl
|
| 6 |
+
SI9sxpcfgf08x1GMrjOWAAAAFm1yb2xhbmRvQGNlaWJhbC5lZHUudXkBAgMEBQYH
|
| 7 |
+
-----END OPENSSH PRIVATE KEY-----
|
hugg.pub
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINbIHCPzbRIoZKdB7yyEKLOlSI9sxpcfgf08x1GMrjOW mrolando@ceibal.edu.uy
|