peterbonnesoeur commited on
Commit
2ab2985
β€’
1 Parent(s): 411e32e

Update app.py

Browse files

Fix new gradio format

Files changed (1) hide show
  1. app.py +23 -25
app.py CHANGED
@@ -2,60 +2,58 @@ import os
2
  import gradio as gr
3
 
4
  def inference(img, ver, white_overlay):
5
-
6
  if white_overlay:
7
  white_overlay = "--white-overlay=0.3"
8
  else:
9
  white_overlay = ""
10
 
11
  if ver == 'pose':
12
- os.system("python -m openpifpaf.predict "+img.name+" --checkpoint=shufflenetv2k30 --line-width=4 " + white_overlay + " -o out.jpg")
13
  elif ver == 'whole-body':
14
- os.system("python -m openpifpaf.predict "+img.name+" --checkpoint=shufflenetv2k30-wholebody --instance-threshold 0.05 " + white_overlay + " --seed-threshold 0.05 \
15
  --line-width 3 -o out.jpg")
16
  elif ver == 'vehicles':
17
- os.system("python -m openpifpaf.predict "+img.name+" --checkpoint=shufflenetv2k16-apollo-24 --line-width=5 " + white_overlay + " -o out.jpg")
18
  elif ver == 'animal':
19
- os.system("python -m openpifpaf.predict "+img.name+" --checkpoint=shufflenetv2k30-animalpose --line-width=5 --font-size=6 " + white_overlay + " \
20
  --long-edge=500 -o out.jpg")
21
  else:
22
  raise ValueError('invalid version')
23
 
24
  return "out.jpg"
25
-
26
-
27
  title = "Openpifpaf - pose estimation for human, vehicles and animals"
28
  description = "Gradio demo for openpifpaf. To use it, simply upload your image, or click one of the examples to load them. Read more at the links below and don't hesitate to SMASH THAT LIKE BUTTON (and you do not have a dislike there either so...)"
29
  article = "<p style='text-align: center'><a href='https://github.com/openpifpaf/openpifpaf' target='_blank'>Github Repo Openpifpaf</a> | <a href='https://github.com/peterbonnesoeur' target='_blank'>Github Repo peterbonnesoeur</a></p>"
30
 
31
  with open("article.html", "r", encoding='utf-8') as f:
32
- article= f.read()
33
-
34
- examples=[
35
- ['basketball.jpg','whole-body'],
36
- ['bill.png','whole-body'],
37
- ['billie.png','whole-body'],
38
- ['meeting.jpeg','pose'],
39
- ['crowd.jpg','pose'],
40
  ['dalmatian.jpg', 'animal'],
41
  ['tappo_loomo.jpg', 'animal'],
42
  ['cow.jpg', 'animal'],
43
  ['india-vehicles.jpeg', 'vehicles'],
44
  ['russia-vehicles.jpg', 'vehicles'],
45
  ['paris-vehicles.jpg', 'vehicles'],
46
-
47
- ]
48
 
49
  gr.Interface(
50
- inference,
51
- [
52
- gr.inputs.Image(type="file", label="Input"),
53
- gr.inputs.Radio(['whole-body', 'pose', 'vehicles', 'animal'], type="value", default='whole-body', label='version'),
54
- gr.inputs.Checkbox(default=False, label="White overlay")
55
  ],
56
- gr.outputs.Image(type="file", label="Output"),
57
  title=title,
58
  description=description,
59
  article=article,
60
- enable_queue=True,
61
- examples=examples).launch()
 
 
2
  import gradio as gr
3
 
4
  def inference(img, ver, white_overlay):
 
5
  if white_overlay:
6
  white_overlay = "--white-overlay=0.3"
7
  else:
8
  white_overlay = ""
9
 
10
  if ver == 'pose':
11
+ os.system("python -m openpifpaf.predict "+img+" --checkpoint=shufflenetv2k30 --line-width=4 " + white_overlay + " -o out.jpg")
12
  elif ver == 'whole-body':
13
+ os.system("python -m openpifpaf.predict "+img+" --checkpoint=shufflenetv2k30-wholebody --instance-threshold 0.05 " + white_overlay + " --seed-threshold 0.05 \
14
  --line-width 3 -o out.jpg")
15
  elif ver == 'vehicles':
16
+ os.system("python -m openpifpaf.predict "+img+" --checkpoint=shufflenetv2k16-apollo-24 --line-width=5 " + white_overlay + " -o out.jpg")
17
  elif ver == 'animal':
18
+ os.system("python -m openpifpaf.predict "+img+" --checkpoint=shufflenetv2k30-animalpose --line-width=5 --font-size=6 " + white_overlay + " \
19
  --long-edge=500 -o out.jpg")
20
  else:
21
  raise ValueError('invalid version')
22
 
23
  return "out.jpg"
24
+
 
25
  title = "Openpifpaf - pose estimation for human, vehicles and animals"
26
  description = "Gradio demo for openpifpaf. To use it, simply upload your image, or click one of the examples to load them. Read more at the links below and don't hesitate to SMASH THAT LIKE BUTTON (and you do not have a dislike there either so...)"
27
  article = "<p style='text-align: center'><a href='https://github.com/openpifpaf/openpifpaf' target='_blank'>Github Repo Openpifpaf</a> | <a href='https://github.com/peterbonnesoeur' target='_blank'>Github Repo peterbonnesoeur</a></p>"
28
 
29
  with open("article.html", "r", encoding='utf-8') as f:
30
+ article = f.read()
31
+
32
+ examples = [
33
+ ['basketball.jpg', 'whole-body'],
34
+ ['bill.png', 'whole-body'],
35
+ ['billie.png', 'whole-body'],
36
+ ['meeting.jpeg', 'pose'],
37
+ ['crowd.jpg', 'pose'],
38
  ['dalmatian.jpg', 'animal'],
39
  ['tappo_loomo.jpg', 'animal'],
40
  ['cow.jpg', 'animal'],
41
  ['india-vehicles.jpeg', 'vehicles'],
42
  ['russia-vehicles.jpg', 'vehicles'],
43
  ['paris-vehicles.jpg', 'vehicles'],
44
+ ]
 
45
 
46
  gr.Interface(
47
+ fn=inference,
48
+ inputs=[
49
+ gr.Image(type="filepath", label="Input"),
50
+ gr.Radio(['whole-body', 'pose', 'vehicles', 'animal'], type="value", default='whole-body', label='version'),
51
+ gr.Checkbox(default=False, label="White overlay")
52
  ],
53
+ outputs=gr.Image(type="filepath", label="Output"),
54
  title=title,
55
  description=description,
56
  article=article,
57
+ examples=examples,
58
+ enable_queue=True
59
+ ).launch()