Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,11 @@
|
|
|
|
1 |
|
2 |
-
pip3 install torch
|
3 |
import torch
|
|
|
4 |
from torch import nn
|
5 |
-
from pathlib import Path
|
6 |
|
7 |
|
8 |
-
|
9 |
-
LABELS=Path('class_names.txt').read_text().splitlines()
|
10 |
|
11 |
model = nn.Sequential(
|
12 |
nn.Conv2d(1, 32, 3, padding='same'),
|
@@ -23,11 +22,7 @@ model = nn.Sequential(
|
|
23 |
nn.ReLU(),
|
24 |
nn.Linear(256, len(LABELS)),
|
25 |
)
|
26 |
-
|
27 |
-
state_dict=torch.load('pytorch_model.bin',map_location='cpu')
|
28 |
-
|
29 |
-
import gradio as gr
|
30 |
-
|
31 |
model.load_state_dict(state_dict, strict=False)
|
32 |
model.eval()
|
33 |
|
@@ -43,14 +38,13 @@ def predict(im):
|
|
43 |
|
44 |
return {LABELS[i]: v.item() for i, v in zip(indices, values)}
|
45 |
|
46 |
-
interface=gr.Interface(
|
47 |
-
predict,
|
48 |
-
inputs="sketchpad",
|
49 |
-
outputs='label',
|
50 |
-
theme="huggingface",
|
51 |
-
title="Sketch Recognition",
|
52 |
-
description="
|
53 |
article = "<p style='text-align: center'>Sketch Recognition | Demo Model</p>",
|
54 |
live=True)
|
55 |
-
interface.launch(
|
56 |
-
|
|
|
1 |
+
from pathlib import Path
|
2 |
|
|
|
3 |
import torch
|
4 |
+
import gradio as gr
|
5 |
from torch import nn
|
|
|
6 |
|
7 |
|
8 |
+
LABELS = Path('class_names.txt').read_text().splitlines()
|
|
|
9 |
|
10 |
model = nn.Sequential(
|
11 |
nn.Conv2d(1, 32, 3, padding='same'),
|
|
|
22 |
nn.ReLU(),
|
23 |
nn.Linear(256, len(LABELS)),
|
24 |
)
|
25 |
+
state_dict = torch.load('pytorch_model.bin', map_location='cpu')
|
|
|
|
|
|
|
|
|
26 |
model.load_state_dict(state_dict, strict=False)
|
27 |
model.eval()
|
28 |
|
|
|
38 |
|
39 |
return {LABELS[i]: v.item() for i, v in zip(indices, values)}
|
40 |
|
41 |
+
interface = gr.Interface(
|
42 |
+
predict,
|
43 |
+
inputs="sketchpad",
|
44 |
+
outputs='label',
|
45 |
+
theme="huggingface",
|
46 |
+
title="Sketch Recognition",
|
47 |
+
description="Who wants to play Pictionary? Draw a common object like a shovel or a laptop, and the algorithm will guess in real time!",
|
48 |
article = "<p style='text-align: center'>Sketch Recognition | Demo Model</p>",
|
49 |
live=True)
|
50 |
+
interface.launch(debug=True)
|
|