Omnibus commited on
Commit
6c0cb15
·
1 Parent(s): 596da82

Create canvas.py

Browse files
Files changed (1) hide show
  1. canvas.py +63 -0
canvas.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ load_js = """
4
+ async () => {
5
+ const url = "https://huggingface.co/datasets/mishig/gradio-components/raw/main/mannequinAll.js"
6
+ fetch(url)
7
+ .then(res => res.text())
8
+ .then(text => {
9
+ const script = document.createElement('script');
10
+ script.type = "module"
11
+ script.src = URL.createObjectURL(new Blob([text], { type: 'application/javascript' }));
12
+ document.head.appendChild(script);
13
+ });
14
+ }
15
+ """
16
+
17
+ get_js_image = """
18
+ async (canvas, prompt) => {
19
+ const poseMakerEl = document.querySelector("pose-maker");
20
+ const imgBase64 = poseMakerEl.captureScreenshotDepthMap();
21
+ return [imgBase64, prompt]
22
+ }
23
+ """
24
+ js_change_rotation_axis = """
25
+ async (axis) => {
26
+ const poseMakerEl = document.querySelector("pose-maker");
27
+ poseMakerEl.changeRotationAxis(axis);
28
+ }
29
+ """
30
+
31
+ js_pose_template = """
32
+ async (pose) => {
33
+ const poseMakerEl = document.querySelector("pose-maker");
34
+ poseMakerEl.setPose(pose);
35
+ }
36
+ """
37
+
38
+ def placeholder_fn(axis):
39
+ pass
40
+
41
+
42
+
43
+ gr.Interface(
44
+ rotation_axis = gr.Radio(["x", "y", "z"], value="x", label="Joint rotation axis")
45
+ pose_template = gr.Radio(["regular", "ballet", "handstand", "split", "kick", "chilling"], value="regular", label="Pose template")
46
+ run_button = gr.Button("Generate")
47
+
48
+
49
+ rotation_axis.change(fn=placeholder_fn,
50
+ inputs=[rotation_axis],
51
+ outputs=[],
52
+ queue=False,
53
+ _js=js_change_rotation_axis)
54
+ pose_template.change(fn=placeholder_fn,
55
+ inputs=[pose_template],
56
+ outputs=[],
57
+ queue=False,
58
+ _js=js_pose_template)
59
+ run_button.click(fn=generate_images,
60
+ inputs=[canvas, prompt],
61
+ outputs=[gallery],
62
+ _js=get_js_image)
63
+ ).load()