Masaki Takano commited on
Commit
1269270
·
1 Parent(s): 5a470be
Files changed (1) hide show
  1. app.py +39 -2
app.py CHANGED
@@ -3,5 +3,42 @@ import gradio as gr
3
  def greet(name):
4
  return "Hello " + name + "!!"
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  def greet(name):
4
  return "Hello " + name + "!!"
5
 
6
+ def predict(model, image, device):
7
+ pred_fun = torch.nn.Softmax(dim=1)
8
+ preds = []
9
+ with torch.set_grad_enabled(False):
10
+ x = image.to(device)
11
+ y = pred_fun(model(x))
12
+ y = y.cpu().numpy()
13
+ y = y[:, 1] # cat:0, dog: 1
14
+ preds.append(y)
15
+ preds = np.concatenate(preds)
16
+ return preds
17
+
18
+ def process_image(input_image, output_type):
19
+ model = torch.load('models/tenichi_noentry.pth')
20
+ preds = predict(model, input_image, 'cpu')
21
+ return preds
22
+
23
+
24
+ iface = gr.Interface(
25
+ fn=process_image,
26
+ inputs=[
27
+ gr.Image(type="pil", label="Input Image", height=512),
28
+ ],
29
+ outputs=gr.Label(label="Output", show_label=False),
30
+ description="天下一品 or 進入禁止"
31
+ # examples=[
32
+ # ["1.png", "Default"],
33
+ # ["2.png", "Default"],
34
+ # ["3.jfif", "Default"],
35
+ # ["4.webp", "Default"]
36
+ # ],
37
+ # cache_examples=True
38
+ )
39
+
40
+ if __name__ == "__main__":
41
+ iface.launch()
42
+
43
+ # demo = gr.Interface(fn=greet, inputs="text", outputs="text")
44
+ # demo.launch()