angtrim commited on
Commit
1e561c3
1 Parent(s): a3c3ebf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -4
app.py CHANGED
@@ -69,7 +69,33 @@ def upload_sketch(file):
69
 
70
  scripts = """
71
  async () => {
72
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
 
74
 
75
 
@@ -147,7 +173,7 @@ with gr.Blocks(css="style.css") as demo:
147
  source="canvas", tool="color-sketch", type="pil", image_mode="L",
148
  invert_colors=True, shape=(512, 512), brush_radius=4, height=440, width=440,
149
  brush_color="#000000", interactive=True, show_download_button=False, elem_id="input_image", show_label=False)
150
-
151
  gr.HTML("""
152
  <div class="button-row">
153
  <div id="my-div-pencil" class="pad2"> <button id="my-toggle-pencil" onclick="return togglePencil(this)"></button> </div>
@@ -168,9 +194,9 @@ with gr.Blocks(css="style.css") as demo:
168
 
169
  demo.load(None,None,None,_js=scripts)
170
  inputs = [image, item]
171
- outputs = [result]
172
  item.change(fn=run, inputs=inputs, outputs=outputs)
173
- image.change(run, inputs=inputs, outputs=outputs,)
174
 
175
  if __name__ == "__main__":
176
  demo.queue().launch(debug=True)
 
69
 
70
  scripts = """
71
  async () => {
72
+
73
+ globalThis.theSketchDownloadFunction = () => {
74
+ console.log("test")
75
+ var link = document.createElement("a");
76
+ dataUri = document.getElementById('download_sketch').href
77
+ link.setAttribute("href", dataUri)
78
+ link.setAttribute("download", "sketch.png")
79
+ document.body.appendChild(link); // Required for Firefox
80
+ link.click();
81
+ document.body.removeChild(link); // Clean up
82
+
83
+ // also call the output download function
84
+ theOutputDownloadFunction();
85
+ return false
86
+ }
87
+
88
+ globalThis.theOutputDownloadFunction = () => {
89
+ console.log("test output download function")
90
+ var link = document.createElement("a");
91
+ dataUri = document.getElementById('download_output').href
92
+ link.setAttribute("href", dataUri);
93
+ link.setAttribute("download", "output.png");
94
+ document.body.appendChild(link); // Required for Firefox
95
+ link.click();
96
+ document.body.removeChild(link); // Clean up
97
+ return false
98
+ }
99
 
100
 
101
 
 
173
  source="canvas", tool="color-sketch", type="pil", image_mode="L",
174
  invert_colors=True, shape=(512, 512), brush_radius=4, height=440, width=440,
175
  brush_color="#000000", interactive=True, show_download_button=False, elem_id="input_image", show_label=False)
176
+ download_sketch = gr.Button("Download sketch", scale=1, elem_id="download_sketch")
177
  gr.HTML("""
178
  <div class="button-row">
179
  <div id="my-div-pencil" class="pad2"> <button id="my-toggle-pencil" onclick="return togglePencil(this)"></button> </div>
 
194
 
195
  demo.load(None,None,None,_js=scripts)
196
  inputs = [image, item]
197
+ outputs = [result, download_sketch, download_output]
198
  item.change(fn=run, inputs=inputs, outputs=outputs)
199
+ image.change(fn=run, inputs=inputs, outputs=outputs,)
200
 
201
  if __name__ == "__main__":
202
  demo.queue().launch(debug=True)