HuggingDavid commited on
Commit
5940022
1 Parent(s): be75422

Upload with huggingface_hub

Browse files
Files changed (3) hide show
  1. app.py +5 -7
  2. three-italic.jpg +0 -0
  3. three2.jpg +0 -0
app.py CHANGED
@@ -4,27 +4,25 @@ 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()
 
4
  from PIL import ImageOps
5
 
6
  def load_model():
7
+ model_dict = torch.load('gradio-app/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).resize((28,28))
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>Write a number, 7 or 3, in the middle.</center></p>'
 
22
 
23
  gr.Interface(fn=predict,
24
+ inputs=gr.Paint(type="pil", invert_colors=True),
25
  outputs=gr.Label(num_top_classes=2),
26
  title=title,
27
  description=description,
28
+ allow_flagging='never').launch()
 
three-italic.jpg ADDED
three2.jpg ADDED