Diego Carpintero commited on
Commit
c726874
·
1 Parent(s): bd42f73

add app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -4
app.py CHANGED
@@ -1,7 +1,46 @@
1
  import gradio as gr
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import torch
3
+ from model import *
4
 
5
+ from PIL import Image
6
+ import torchvision.transforms as transforms
7
 
8
+
9
+ title = "Fashion Image Recognition"
10
+ inputs = gr.components.Image()
11
+ outputs = gr.components.Label()
12
+ examples = "examples"
13
+
14
+ model = torch.load("model/fashion.mnist.base.pt", map_location=torch.device("cpu"))
15
+
16
+ # Images need to be transformed to an approximated `fashion MNIST` dataset format
17
+ # see https://arxiv.org/abs/1708.07747
18
+ transform = transforms.Compose(
19
+ [
20
+ transforms.Resize((28, 28)),
21
+ transforms.Grayscale(),
22
+ transforms.ToTensor(),
23
+ transforms.Normalize((0.5,), (0.5,)), # Normalization
24
+ transforms.Lambda(lambda x: 1.0 - x), # Invert colors
25
+ transforms.Lambda(lambda x: x[0]),
26
+ transforms.Lambda(lambda x: x.unsqueeze(0)),
27
+ ]
28
+ )
29
+
30
+
31
+ def predict(img):
32
+ img = transform(Image.fromarray(img))
33
+ predictions = model.predictions(img)
34
+ return predictions
35
+
36
+
37
+ with gr.Blocks() as demo:
38
+ with gr.Tab("Garment Prediction"):
39
+ gr.Interface(
40
+ fn=predict,
41
+ inputs=inputs,
42
+ outputs=outputs,
43
+ examples=examples,
44
+ ).queue(default_concurrency_limit=5)
45
+
46
+ demo.launch()