Spaces:
Runtime error
Runtime error
organized the size-related aspects
Browse files- app.py +17 -7
- 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 |
-
|
|
|
|
|
|
|
|
|
58 |
|
59 |
-
|
|
|
|
|
|
|
|
|
60 |
fn = None,
|
61 |
-
inputs =
|
62 |
-
_js="(
|
63 |
-
|
64 |
-
|
|
|
|
|
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 |
-
|
159 |
-
|
160 |
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
|
165 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
}
|