MAnthony commited on
Commit
d0f2df5
·
verified ·
1 Parent(s): ca7c022

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -22
app.py CHANGED
@@ -6,19 +6,8 @@ from tf_bodypix.api import download_model, load_model, BodyPixModelPaths
6
  import numpy as np
7
  from PIL import Image
8
 
9
- def greet(name):
10
- # setup input and output paths
11
- output_path = Path('./data/example-output')
12
- output_path.mkdir(parents=True, exist_ok=True)
13
- input_url = (
14
- 'https://www.dropbox.com/s/7tsaqgdp149d8aj/serious-black-businesswoman-sitting-at-desk-in-office-5669603.jpg?dl=1'
15
- )
16
- local_input_path = tf.keras.utils.get_file(origin=input_url)
17
-
18
- #input_path = 'IMG_7522.jpg'
19
- image = tf.keras.preprocessing.image.load_img(local_input_path)
20
-
21
- # load model (once)
22
  modelPath = download_model(BodyPixModelPaths.RESNET50_FLOAT_STRIDE_16)
23
  bodypix_model = load_model(modelPath)
24
 
@@ -29,21 +18,13 @@ def greet(name):
29
 
30
  # simple mask
31
  mask = result.get_mask(threshold=0.75)
32
- tf.keras.preprocessing.image.save_img(
33
- f'{output_path}/output-mask.jpg',
34
- mask
35
- )
36
 
37
  # colored mask (separate colour for each body part)
38
  colored_mask = result.get_colored_part_mask(mask)
39
- tf.keras.preprocessing.image.save_img(
40
- f'{output_path}/output-colored-mask.jpg',
41
- colored_mask
42
- )
43
 
44
  colored_mask_image = Image.fromarray(colored_mask.astype('uint8'), 'RGB')
45
 
46
  return colored_mask_image;
47
 
48
- iface = gr.Interface(fn=greet, inputs="text", outputs="image")
49
  iface.launch()
 
6
  import numpy as np
7
  from PIL import Image
8
 
9
+ def predict(local_input_path):
10
+ # load model
 
 
 
 
 
 
 
 
 
 
 
11
  modelPath = download_model(BodyPixModelPaths.RESNET50_FLOAT_STRIDE_16)
12
  bodypix_model = load_model(modelPath)
13
 
 
18
 
19
  # simple mask
20
  mask = result.get_mask(threshold=0.75)
 
 
 
 
21
 
22
  # colored mask (separate colour for each body part)
23
  colored_mask = result.get_colored_part_mask(mask)
 
 
 
 
24
 
25
  colored_mask_image = Image.fromarray(colored_mask.astype('uint8'), 'RGB')
26
 
27
  return colored_mask_image;
28
 
29
+ iface = gr.Interface(fn=predict, inputs="image", outputs="image")
30
  iface.launch()