fix import
Browse filesFiles changed (2)
- app.py+36-11
- static/poseEditor.js+25-17
69 unmodified lines7071727374757677787980818283848586878889909192937 unmodified lines10110210310410510610711 unmodified lines1191201211221231241251261271281291301311321331 unmodified line13513613713813969 unmodified linesdef image_changed(image):if (image == None):return {}, 512, 512json = estimate_body(image)return json, image.width, image.heighthtml_text = f"""<canvas id="canvas" width="512" height="512"></canvas><script type="text/javascript" defer>{file_contents}</script>"""with gr.Blocks() as demo:with gr.Row():with gr.Column(scale=1):startBtn = gr.Button(value="Start edit")width = gr.Slider(label="Width", minimum=512, maximum=1024, step=64, value=512, interactive=True)height = gr.Slider(label="Height", minimum=512, maximum=1024, step=64, value=512, interactive=True)with gr.Accordion(label="Pose estimation", open=False):source = gr.Image(type="pil")gr.Markdown("""push "Start edit" after estimation done.""")with gr.Accordion(label="Json", open=False):gr.Markdown("""| inout | how to |7 unmodified lineswith gr.Column(scale=2):html = gr.HTML(html_text)with gr.Row():with gr.Column(scale=1):saveBtn = gr.Button(value="Save")with gr.Column(scale=7):gr.Markdown("""11 unmodified linesPoints to note for pseudo-3D rotation: When performing pseudo-3D rotation on the X and Y axes, the projection is converted to 2D and Z-axis information is lost when the mouse button is released. This means that if you finish dragging while the shape is collapsed, you may not be able to restore it to its original state. In such a case, please use the "undo" function.""")source.change(fn = image_changed,inputs = [source],outputs = [json, width, height])startBtn.click(fn = None,inputs = [json, width, height],outputs = [],_js="(json, w, h) => { initializePose(json,w,h); return []; }")saveBtn.click(fn = None,inputs = [], outputs = [json],1 unmodified linejsonInputBtn.click(fn = lambda x: x,inputs = [jsonInput], outputs = [json])gr.mount_gradio_app(app, demo, path="/")69 unmodified lines7071727374757677787980818283848586878889909192939495969798991001011021031047 unmodified lines11211311411511611711811 unmodified lines1301311321331341351361371381391401411421431441451461471481491501511521531541551561571 unmodified line15916016116216316469 unmodified linesdef image_changed(image):if (image == None):return "estimation", {}#json = estimate_body(image)candidate, subset = body_estimation(pil2cv(image))print(subset.shape)json = "{ \"candidate\": " + candidate_to_json_string(candidate) + ", \"subset\": " + subset_to_json_string(subset) + " }"return f"""{image.width}px x {image.height}px, {subset.shape[0]} indivisual(s)""", jsonhtml_text = f"""<canvas id="canvas" width="512" height="512"></canvas><script type="text/javascript" defer>{file_contents}</script>"""with gr.Blocks(css="""button { min-width: 80px; }""") as demo:with gr.Row():with gr.Column(scale=1):width = gr.Slider(label="Width", minimum=512, maximum=1024, step=64, value=512, interactive=True)height = gr.Slider(label="Height", minimum=512, maximum=1024, step=64, value=512, interactive=True)with gr.Accordion(label="Pose estimation", open=False):source = gr.Image(type="pil")estimationResult = gr.Markdown("""estimation""")with gr.Row():with gr.Column(min_width=80):applySizeBtn = gr.Button(value="Apply size")with gr.Column(min_width=80):replaceBtn = gr.Button(value="Replace")with gr.Column(min_width=80):importBtn = gr.Button(value="Import")with gr.Accordion(label="Json", open=False):gr.Markdown("""| inout | how to |7 unmodified lineswith gr.Column(scale=2):html = gr.HTML(html_text)with gr.Row():with gr.Column(scale=1, min_width=60):saveBtn = gr.Button(value="Save")with gr.Column(scale=7):gr.Markdown("""11 unmodified linesPoints to note for pseudo-3D rotation: When performing pseudo-3D rotation on the X and Y axes, the projection is converted to 2D and Z-axis information is lost when the mouse button is released. This means that if you finish dragging while the shape is collapsed, you may not be able to restore it to its original state. In such a case, please use the "undo" function.""")width.change(fn=None, inputs=[width], _js="(w) => { resizeCanvas(w,null); }")height.change(fn=None, inputs=[height], _js="(h) => { resizeCanvas(null,h); }")source.change(fn = image_changed,inputs = [source],outputs = [estimationResult, json])applySizeBtn.click(fn = lambda x: (x.width, x.height),inputs = [source],outputs = [width, height])replaceBtn.click(fn = None,inputs = [json],outputs = [],_js="(json) => { initializeEditor(); importPose(json); return []; }")importBtn.click(fn = None,inputs = [json],outputs = [],_js="(json) => { importPose(json); return []; }")saveBtn.click(fn = None,inputs = [], outputs = [json],1 unmodified linejsonInputBtn.click(fn = lambda x: x,inputs = [jsonInput], outputs = [json])demo.load(fn=None, inputs=[], outputs=[], _js="() => { initializeEditor(); importPose(); return []; }")gr.mount_gradio_app(app, demo, path="/")
39 unmodified lines4041424344454640 unmodified lines8788899091929394959697989910068 unmodified lines16917017117217317417588 unmodified lines264265266267268269186 unmodified lines4564574584594604614624634644654664674684691 unmodified line47147247347447547647747847948039 unmodified linesvar pose = [];for (let j = 0 ; j < 18; j++) {let i = subsetElement[j];pose.push(i < 0 ? null : candidate[i]);}return pose;}40 unmodified linesfunction resizeCanvas(width, height) {canvas.width = width ? width : canvas.width;canvas.height = height ? height : canvas.height;clearCanvas();drawBodyPose();}function calculateCenter(shape) {var center = shape.reduce(function(acc, point) {acc[0] += point[0];acc[1] += point[1];return acc;}, [0, 0]);center[0] /= shape.length;68 unmodified linesfor (let i = 0; i < poseData.length; i++) {const pose = poseData[i];const center = calculateCenter(pose);// edgefor (let j = 0; j < 17; j++) {88 unmodified lineslet history = [];let historyIndex = 0;function addHistory() {history = history.slice(0, historyIndex);history.push(JSON.parse(JSON.stringify(poseData)));186 unmodified linesRedraw();});function initializePose(jsonData,w,h) {console.log("initializePose");if (jsonData != null) {poseData = makePoseDataFromCandidateAndSubset(jsonData.candidate, jsonData.subset);} else {poseData = makePoseDataFromCandidateAndSubset(sampleCandidateSource, [sampleSubsetElementSource]);}addHistory();canvas = document.getElementById('canvas');ctx = canvas.getContext('2d');1 unmodified linecanvas.addEventListener('mousedown', handleMouseDown);canvas.addEventListener('mousemove', handleMouseMove);canvas.addEventListener('mouseup', handleMouseUp);resizeCanvas(w, h);// setInterval(Redraw, 1000 / 30);}function savePose() {39 unmodified lines4041424344454640 unmodified lines8788899091929394959697989910010168 unmodified lines17017117217317417588 unmodified lines264265266267268269270271272273274186 unmodified lines4614624634644654664674681 unmodified line47047147247347447547647747847948048148248348448548648748839 unmodified linesvar pose = [];for (let j = 0 ; j < 18; j++) {let i = subsetElement[j];pose.push(i < 0 ? null : candidate[i].map((x)=>x));}return pose;}40 unmodified linesfunction resizeCanvas(width, height) {canvas.width = width ? width : canvas.width;canvas.height = height ? height : canvas.height;Redraw();}function calculateCenter(shape) {var center = shape.reduce(function(acc, point) {if (point === null) {acc[0] += point[0];acc[1] += point[1];}return acc;}, [0, 0]);center[0] /= shape.length;68 unmodified linesfor (let i = 0; i < poseData.length; i++) {const pose = poseData[i];// edgefor (let j = 0; j < 17; j++) {88 unmodified lineslet history = [];let historyIndex = 0;function clearHistory() {history = [];historyIndex = 0;}function addHistory() {history = history.slice(0, historyIndex);history.push(JSON.parse(JSON.stringify(poseData)));186 unmodified linesRedraw();});function initializeEditor() {console.log("initializeEditor");canvas = document.getElementById('canvas');ctx = canvas.getContext('2d');1 unmodified linecanvas.addEventListener('mousedown', handleMouseDown);canvas.addEventListener('mousemove', handleMouseMove);canvas.addEventListener('mouseup', handleMouseUp);poseData = [];clearHistory();}function importPose(jsonData) {if (jsonData != null) {newPoseData = makePoseDataFromCandidateAndSubset(jsonData.candidate, jsonData.subset);} else {newPoseData = makePoseDataFromCandidateAndSubset(sampleCandidateSource, [sampleSubsetElementSource]);}poseData = poseData.concat(newPoseData);addHistory();Redraw();}function savePose() {
app.py+36-11
static/poseEditor.js+25-17