jonigata commited on
Commit
16a0676
·
1 Parent(s): 8ce67ab

suppress error on clear image

Browse files
Files changed (1) hide show
  1. app.py +22 -11
app.py CHANGED
@@ -62,45 +62,53 @@ def subset_to_json_string(arr):
62
  return '[' + arr_str + ']'
63
 
64
  def estimate_body(source):
65
- print("estimate_body")
66
  if source == None:
67
  return None
68
 
69
  candidate, subset = body_estimation(pil2cv(source))
70
- print(candidate_to_json_string(candidate))
71
- print(subset_to_json_string(subset))
72
  return "{ \"candidate\": " + candidate_to_json_string(candidate) + ", \"subset\": " + subset_to_json_string(subset) + " }"
73
 
74
  def image_changed(image):
75
  if (image == None):
76
- return None
77
  json = estimate_body(image)
78
  return json, image.width, image.height
79
 
80
- def image_preprocess(image):
81
- return image is not None
82
-
83
  html_text = f"""
84
  <canvas id="canvas" width="512" height="512"></canvas>
85
  <script type="text/javascript" defer>{file_contents}</script>
86
  """
87
 
88
  with gr.Blocks() as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  with gr.Row():
90
  with gr.Column(scale=1):
91
  source = gr.Image(type="pil")
92
  width = gr.Slider(label="Width", mininmum=512, maximum=1024, step=64, value=512, key="Width", interactive=True)
93
  height = gr.Slider(label="Height", mininmum=512, maximum=1024, step=64, value=512, key="Height", interactive=True)
94
  startBtn = gr.Button(value="Start edit")
95
- json = gr.JSON(label="Body")
 
 
96
  with gr.Column(scale=2):
97
- gr.HTML("<ul><li>ctrl + drag to scale</li><li>alt + drag to translate</li><li>shift + drag to rotate(move right first, then up or down)</li></ul>")
98
  html = gr.HTML(html_text)
99
  saveBtn = gr.Button(value="Save")
 
100
 
101
  source.change(
102
  fn = image_changed,
103
- preprocess = image_preprocess,
104
  inputs = [source],
105
  outputs = [json, width, height])
106
  startBtn.click(
@@ -112,5 +120,8 @@ with gr.Blocks() as demo:
112
  fn = None,
113
  inputs = [], outputs = [json],
114
  _js="() => { return [savePose()]; }")
115
-
 
 
 
116
  gr.mount_gradio_app(app, demo, path="/")
 
62
  return '[' + arr_str + ']'
63
 
64
  def estimate_body(source):
 
65
  if source == None:
66
  return None
67
 
68
  candidate, subset = body_estimation(pil2cv(source))
 
 
69
  return "{ \"candidate\": " + candidate_to_json_string(candidate) + ", \"subset\": " + subset_to_json_string(subset) + " }"
70
 
71
  def image_changed(image):
72
  if (image == None):
73
+ return {}, 512, 512
74
  json = estimate_body(image)
75
  return json, image.width, image.height
76
 
 
 
 
77
  html_text = f"""
78
  <canvas id="canvas" width="512" height="512"></canvas>
79
  <script type="text/javascript" defer>{file_contents}</script>
80
  """
81
 
82
  with gr.Blocks() as demo:
83
+ gr.Markdown("""### Usage
84
+
85
+ Choose one of the following methods to edit the pose:
86
+
87
+ | Style | Description |
88
+ | -----------------| ----------------------------------------------------------------------------------------- |
89
+ | Pose recognition | Upload an image and click "Start edit". |
90
+ | Input json | Input json to "Json source" and click "Input Json", edit the width/height, then click "Start edit". |
91
+ | Free style | Edit the width/height, then click "Start edit". |
92
+
93
+ To save the pose image, click "Save".
94
+ To export the pose data, click "Save" and "Copy to clipboard" of "Json" section.
95
+ """)
96
  with gr.Row():
97
  with gr.Column(scale=1):
98
  source = gr.Image(type="pil")
99
  width = gr.Slider(label="Width", mininmum=512, maximum=1024, step=64, value=512, key="Width", interactive=True)
100
  height = gr.Slider(label="Height", mininmum=512, maximum=1024, step=64, value=512, key="Height", interactive=True)
101
  startBtn = gr.Button(value="Start edit")
102
+ json = gr.JSON(label="Json", lines=10)
103
+ jsonInput = gr.Textbox(label="Json source", lines=10)
104
+ jsonInputBtn = gr.Button(value="Input Json")
105
  with gr.Column(scale=2):
 
106
  html = gr.HTML(html_text)
107
  saveBtn = gr.Button(value="Save")
108
+ gr.HTML("<ul><li>ctrl + drag to scale</li><li>alt + drag to translate</li><li>shift + drag to rotate(move right first, then up or down)</li></ul>")
109
 
110
  source.change(
111
  fn = image_changed,
 
112
  inputs = [source],
113
  outputs = [json, width, height])
114
  startBtn.click(
 
120
  fn = None,
121
  inputs = [], outputs = [json],
122
  _js="() => { return [savePose()]; }")
123
+ jsonInputBtn.click(
124
+ fn = lambda x: x,
125
+ inputs = [jsonInput], outputs = [json])
126
+
127
  gr.mount_gradio_app(app, demo, path="/")