Spaces:
Runtime error
Runtime error
HuggingDavid
commited on
Commit
·
aa56c48
1
Parent(s):
34f9ae3
Upload with huggingface_hub
Browse files
app.py
CHANGED
@@ -1,7 +1,30 @@
|
|
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
-
def
|
4 |
-
|
|
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
import gradio as gr
|
3 |
+
from torchvision import transforms
|
4 |
+
from PIL import ImageOps
|
5 |
|
6 |
+
def load_model():
|
7 |
+
model_dict = torch.load('linear_model.pt')
|
8 |
+
return model_dict
|
9 |
|
10 |
+
model = load_model()
|
11 |
+
convert_tensor = transforms.ToTensor()
|
12 |
+
|
13 |
+
def predict(img):
|
14 |
+
img = ImageOps.grayscale(img)
|
15 |
+
image_tensor = convert_tensor(img).view(28*28)
|
16 |
+
res = image_tensor @ model['weights'] + model['bias']
|
17 |
+
res = res.sigmoid()
|
18 |
+
return {"It's 3": float(res), "It's 7": float(1-res)}
|
19 |
+
|
20 |
+
title = "Is it 7 or 3"
|
21 |
+
description = '<p><center>Upload an image with a handwritten number: 7 or 3.</center></p>'
|
22 |
+
examples = ['three.png', 'seven.png']
|
23 |
+
|
24 |
+
gr.Interface(fn=predict,
|
25 |
+
inputs=gr.Image(type="pil"),
|
26 |
+
outputs=gr.Label(num_top_classes=2),
|
27 |
+
title=title,
|
28 |
+
description=description,
|
29 |
+
allow_flagging='never',
|
30 |
+
examples=examples).launch()
|
linear_model.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5b7ebfe6cd266359cc4715eceb910d8cf3440496d21bd45d58293c3310ad1481
|
3 |
+
size 4071
|
seven.png
ADDED
three.png
ADDED