lfolle commited on
Commit
c02063c
1 Parent(s): ec42e29

Polished interface a bit.

Browse files
Files changed (3) hide show
  1. .gitignore +2 -1
  2. app.py +26 -22
  3. backend.py +3 -3
.gitignore CHANGED
@@ -1,2 +1,3 @@
1
  .vscode/launch.json
2
- *.pyc
 
1
  .vscode/launch.json
2
+ *.pyc
3
+ gradio_cached_examples/*
app.py CHANGED
@@ -6,37 +6,41 @@ from backend import Infer
6
  DEBUG = True
7
 
8
  infer = Infer(DEBUG)
9
-
10
 
11
  with gr.Blocks(analytics_enabled=False, title="DeepNAPSI") as demo:
 
12
  with gr.Column():
13
  gr.Markdown("## Welcome to the DeepNAPSI application!")
14
  gr.Markdown("Upload an image of the one hand and click **Predict NAPSI** to see the output.\n" \
15
  "> Note: Make sure there are no identifying information present in the image. The prediction can take up to 1 minute.")
16
  with gr.Column():
17
  with gr.Row():
18
- image_input = gr.Image()
19
- example_images = gr.Examples(["assets/example_1.jpg", "assets/example_2.jpg", "assets/example_3.jpg"], image_input)
20
- with gr.Row():
21
- image_button = gr.Button("Predict NAPSI")
22
- outputs = []
23
- with gr.Row():
24
- outputs.append(gr.Number(label="DeepNAPSI Sum"))
25
- with gr.Column():
26
- outputs.append(gr.Image())
27
- outputs.append(gr.Number(label="DeepNAPSI Thumb"))
28
  with gr.Column():
29
- outputs.append(gr.Image())
30
- outputs.append(gr.Number(label="DeepNAPSI Index"))
31
- with gr.Column():
32
- outputs.append(gr.Image())
33
- outputs.append(gr.Number(label="DeepNAPSI Middle"))
34
- with gr.Column():
35
- outputs.append(gr.Image())
36
- outputs.append(gr.Number(label="DeepNAPSI Ring"))
37
- with gr.Column():
38
- outputs.append(gr.Image())
39
- outputs.append(gr.Number(label="DeepNAPSI Pinky"))
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  image_button.click(infer.predict, inputs=image_input, outputs=outputs)
41
 
42
  demo.launch(share=True)
6
  DEBUG = True
7
 
8
  infer = Infer(DEBUG)
9
+ example_image_path = ["assets/example_1.jpg", "assets/example_2.jpg", "assets/example_3.jpg"]
10
 
11
  with gr.Blocks(analytics_enabled=False, title="DeepNAPSI") as demo:
12
+ outputs = []
13
  with gr.Column():
14
  gr.Markdown("## Welcome to the DeepNAPSI application!")
15
  gr.Markdown("Upload an image of the one hand and click **Predict NAPSI** to see the output.\n" \
16
  "> Note: Make sure there are no identifying information present in the image. The prediction can take up to 1 minute.")
17
  with gr.Column():
18
  with gr.Row():
 
 
 
 
 
 
 
 
 
 
19
  with gr.Column():
20
+ with gr.Row():
21
+ image_input = gr.Image()
22
+ with gr.Row():
23
+ image_button = gr.Button("Predict NAPSI")
24
+ with gr.Row():
25
+ with gr.Column():
26
+ outputs.append(gr.Image(label="Thumb"))
27
+ outputs.append(gr.Number(label="DeepNAPSI Thumb", precision=0))
28
+ with gr.Column():
29
+ outputs.append(gr.Image(label="Index"))
30
+ outputs.append(gr.Number(label="DeepNAPSI Index", precision=0))
31
+ with gr.Column():
32
+ outputs.append(gr.Image(label="Middle"))
33
+ outputs.append(gr.Number(label="DeepNAPSI Middle", precision=0))
34
+ with gr.Column():
35
+ outputs.append(gr.Image(label="Ring"))
36
+ outputs.append(gr.Number(label="DeepNAPSI Ring", precision=0))
37
+ with gr.Column():
38
+ outputs.append(gr.Image(label="Pinky"))
39
+ outputs.append(gr.Number(label="DeepNAPSI Pinky", precision=0))
40
+ outputs.append(gr.Number(label="DeepNAPSI Sum", precision=0))
41
+
42
+ example_images = gr.Examples(example_image_path, image_input, outputs,
43
+ fn=infer.predict, cache_examples=True)
44
  image_button.click(infer.predict, inputs=image_input, outputs=outputs)
45
 
46
  demo.launch(share=True)
backend.py CHANGED
@@ -17,17 +17,17 @@ class Infer():
17
  nails = get_nails(cv2.cvtColor(data, cv2.COLOR_RGB2BGR))
18
  predictions = []
19
  if nails is None:
20
- predictions.append(-1)
21
  for _ in range(5):
22
  predictions.append(np.zeros((64, 64, 3)))
23
  predictions.append(-1)
 
24
  else:
25
  model_prediction, uncertainty = self.model(nails)
26
  model_prediction = model_prediction[0]
27
  napsi_predictions = torch.argmax(model_prediction, 1)
28
  napsi_sum = int(napsi_predictions.sum().detach().cpu())
29
- predictions.append(napsi_sum)
30
  for napsi_prediction, nail in zip(napsi_predictions, nails):
31
  predictions.append(nail)
32
- predictions.append(napsi_prediction)
 
33
  return predictions
17
  nails = get_nails(cv2.cvtColor(data, cv2.COLOR_RGB2BGR))
18
  predictions = []
19
  if nails is None:
 
20
  for _ in range(5):
21
  predictions.append(np.zeros((64, 64, 3)))
22
  predictions.append(-1)
23
+ predictions.append("-1")
24
  else:
25
  model_prediction, uncertainty = self.model(nails)
26
  model_prediction = model_prediction[0]
27
  napsi_predictions = torch.argmax(model_prediction, 1)
28
  napsi_sum = int(napsi_predictions.sum().detach().cpu())
 
29
  for napsi_prediction, nail in zip(napsi_predictions, nails):
30
  predictions.append(nail)
31
+ predictions.append(int(napsi_prediction.detach().cpu()))
32
+ predictions.append(napsi_sum)
33
  return predictions