jonigata commited on
Commit
47994fa
1 Parent(s): 6b267c6

organized the size-related aspects

Browse files
Files changed (2) hide show
  1. app.py +17 -7
  2. static/poseEditor.js +20 -7
app.py CHANGED
@@ -49,18 +49,28 @@ with gr.Blocks() as demo:
49
  with gr.Row():
50
  with gr.Column(scale=1):
51
  source = gr.Image(type="pil")
52
- btn = gr.Button(value="Fetch pose")
53
  width = gr.Slider(label="Width", mininmum=512, maximum=1024, step=64, value=512, key="Width", interactive=True)
54
  height = gr.Slider(label="Height", mininmum=512, maximum=1024, step=64, value=512, key="Height", interactive=True)
 
55
  with gr.Column(scale=2):
56
  html = gr.HTML(html_text)
57
- console = gr.Textbox(label="console")
 
 
 
 
58
 
59
- btn.click(
 
 
 
 
60
  fn = None,
61
- inputs = source, outputs = [console, width, height],
62
- _js="(i) => { console.log(typeof(i)); initializePose(); return [i, 1024, 1024]; }")
63
- width.change(fn=None, _js="(i) => { console.log(i); resizeCanvas(i, null); return i; }")
64
- height.change(fn=None, _js="(i) => { console.log(i); resizeCanvas(null, i); return i; }")
 
 
65
 
66
  gr.mount_gradio_app(app, demo, path="/")
 
49
  with gr.Row():
50
  with gr.Column(scale=1):
51
  source = gr.Image(type="pil")
 
52
  width = gr.Slider(label="Width", mininmum=512, maximum=1024, step=64, value=512, key="Width", interactive=True)
53
  height = gr.Slider(label="Height", mininmum=512, maximum=1024, step=64, value=512, key="Height", interactive=True)
54
+ startBtn = gr.Button(value="Start edit")
55
  with gr.Column(scale=2):
56
  html = gr.HTML(html_text)
57
+ with gr.Row():
58
+ with gr.Column(scale=2):
59
+ console = gr.Textbox(label="console")
60
+ with gr.Column(scale=1):
61
+ saveBtn = gr.Button(value="Save")
62
 
63
+ source.change(
64
+ fn=lambda x: x.size,
65
+ inputs = [source],
66
+ outputs = [width, height])
67
+ startBtn.click(
68
  fn = None,
69
+ inputs = [width, height], outputs = [],
70
+ _js="(w, h) => { initializePose(w,h); return []; }")
71
+ saveBtn.click(
72
+ fn = None,
73
+ inputs = source, outputs = console,
74
+ _js="() => { savePose(); }")
75
 
76
  gr.mount_gradio_app(app, demo, path="/")
static/poseEditor.js CHANGED
@@ -154,13 +154,26 @@ function handleMouseUp(event) {
154
  isDragging = false;
155
  }
156
 
157
- function initializePose() {
158
- canvas = document.getElementById('canvas');
159
- ctx = canvas.getContext('2d');
160
 
161
- canvas.addEventListener('mousedown', handleMouseDown);
162
- canvas.addEventListener('mousemove', handleMouseMove);
163
- canvas.addEventListener('mouseup', handleMouseUp);
164
 
165
- resizeCanvas(512, 512);
 
 
 
 
 
 
 
 
 
 
 
 
 
166
  }
 
154
  isDragging = false;
155
  }
156
 
157
+ function initializePose(w,h) {
158
+ canvas = document.getElementById('canvas');
159
+ ctx = canvas.getContext('2d');
160
 
161
+ canvas.addEventListener('mousedown', handleMouseDown);
162
+ canvas.addEventListener('mousemove', handleMouseMove);
163
+ canvas.addEventListener('mouseup', handleMouseUp);
164
 
165
+ resizeCanvas(w, h);
166
+ }
167
+
168
+ function savePose() {
169
+ const canvasUrl = canvas.toDataURL();
170
+
171
+ const createEl = document.createElement('a');
172
+ createEl.href = canvasUrl;
173
+
174
+ // This is the name of our downloaded file
175
+ createEl.download = "pose.png";
176
+
177
+ createEl.click();
178
+ createEl.remove();
179
  }