Spaces:
Runtime error
Runtime error
Delete canvas.py
Browse files
canvas.py
DELETED
@@ -1,72 +0,0 @@
|
|
1 |
-
#This code is from: https://huggingface.co/spaces/diffusers/controlnet-3d-pose
|
2 |
-
import gradio as gr
|
3 |
-
canvas_html = '<pose-maker/>'
|
4 |
-
|
5 |
-
load_js = """
|
6 |
-
async () => {
|
7 |
-
const url = "https://huggingface.co/datasets/mishig/gradio-components/raw/main/mannequinAll.js"
|
8 |
-
fetch(url)
|
9 |
-
.then(res => res.text())
|
10 |
-
.then(text => {
|
11 |
-
const script = document.createElement('script');
|
12 |
-
script.type = "module"
|
13 |
-
script.src = URL.createObjectURL(new Blob([text], { type: 'application/javascript' }));
|
14 |
-
document.head.appendChild(script);
|
15 |
-
});
|
16 |
-
}
|
17 |
-
"""
|
18 |
-
|
19 |
-
get_js_image = """
|
20 |
-
async (canvas, prompt) => {
|
21 |
-
const poseMakerEl = document.querySelector("pose-maker");
|
22 |
-
const imgBase64 = poseMakerEl.captureScreenshotDepthMap();
|
23 |
-
return [imgBase64, prompt]
|
24 |
-
}
|
25 |
-
"""
|
26 |
-
js_change_rotation_axis = """
|
27 |
-
async (axis) => {
|
28 |
-
const poseMakerEl = document.querySelector("pose-maker");
|
29 |
-
poseMakerEl.changeRotationAxis(axis);
|
30 |
-
}
|
31 |
-
"""
|
32 |
-
|
33 |
-
js_pose_template = """
|
34 |
-
async (pose) => {
|
35 |
-
const poseMakerEl = document.querySelector("pose-maker");
|
36 |
-
poseMakerEl.setPose(pose);
|
37 |
-
}
|
38 |
-
"""
|
39 |
-
def generate_images(canvas):
|
40 |
-
base64_img = canvas
|
41 |
-
image_data = base64.b64decode(base64_img.split(',')[1])
|
42 |
-
input_img = Image.open(BytesIO(image_data)).convert(
|
43 |
-
'RGB').resize((512, 512))
|
44 |
-
input_img = input_img.filter(ImageFilter.GaussianBlur(radius=2))
|
45 |
-
input_img = get_canny_filter(input_img)
|
46 |
-
return input_image
|
47 |
-
def placeholder_fn(axis):
|
48 |
-
pass
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
with gr.Blocks() as b:
|
53 |
-
canvas = gr.HTML(canvas_html, elem_id="canvas_html", visible=True)
|
54 |
-
rotation_axis = gr.Radio(choices=["x", "y", "z"], value="x", label="Joint rotation axis")
|
55 |
-
pose_template = gr.Radio(choices=["regular", "ballet", "handstand", "split", "kick", "chilling"], value="regular", label="Pose template")
|
56 |
-
run_button = gr.Button("Generate")
|
57 |
-
|
58 |
-
rotation_axis.change(fn=placeholder_fn,
|
59 |
-
inputs=[rotation_axis],
|
60 |
-
outputs=[],
|
61 |
-
queue=False,
|
62 |
-
_js=js_change_rotation_axis)
|
63 |
-
pose_template.change(fn=placeholder_fn,
|
64 |
-
inputs=[pose_template],
|
65 |
-
outputs=[],
|
66 |
-
queue=False,
|
67 |
-
_js=js_pose_template)
|
68 |
-
run_button.click(fn=generate_images,
|
69 |
-
inputs=[canvas],
|
70 |
-
outputs=[gr.Image()],
|
71 |
-
_js=get_js_image)
|
72 |
-
b.load()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|