diff --git a/javascript/infinite-zoom.js b/javascript/infinite-zoom.js new file mode 100644 index 0000000..8f7d546 --- /dev/null +++ b/javascript/infinite-zoom.js @@ -0,0 +1,54 @@ +// Function to download data to a file +function exportPrompts(p, np, filename = "infinite-zoom-prompts.json") { + + let J = { prompts: p, negPrompt: np } + + var file = new Blob([JSON.stringify(J)], { type: "text/csv" }); + if (window.navigator.msSaveOrOpenBlob) // IE10+ + window.navigator.msSaveOrOpenBlob(file, filename); + else { // Others + var a = document.createElement("a"), + url = URL.createObjectURL(file); + a.href = url; + a.download = filename; + document.body.appendChild(a); + a.click(); + setTimeout(function () { + document.body.removeChild(a); + window.URL.revokeObjectURL(url); + }, 0); + } +} + +document.addEventListener("DOMContentLoaded", () => { + const onload = () => { + + if (typeof gradioApp === "function") { + /* move big buttons directly under the tabl of prompts as SMall ones */ + const wrap = gradioApp().querySelector("#tab_iz_interface .gradio-dataframe .controls-wrap") + + if (wrap) { + let butts = gradioApp().querySelectorAll("#tab_iz_interface .infzoom_tab_butt") + butts.forEach(b => { + wrap.appendChild(b) + b.classList.replace("lg", "sm") // smallest + }); + } + else { + setTimeout(onload, 2000); + } + } + else { + setTimeout(onload, 2000); + } + }; + onload(); +}); + + + + + + + + diff --git a/scripts/inifnite-zoom.py b/scripts/inifnite-zoom.py index 29e6f9a..a102d72 100644 --- a/scripts/inifnite-zoom.py +++ b/scripts/inifnite-zoom.py @@ -8,6 +8,7 @@ import numpy as np import gradio as gr from PIL import Image import math +import json from iz_helpers import shrink_and_paste_on_blank, write_video from webui import wrap_gradio_gpu_call @@ -278,6 +279,17 @@ def create_zoom( ) +def exportPrompts(p,np): + print("prompts:" + str(p) +"\n"+str(np)) + +def putPrompts(files): + file_paths = [file.name for file in files] + with open(files.name, 'r') as f: + file_contents = f.read() + data = json.loads(file_contents) + print(data) + return [gr.DataFrame.update(data["prompts"]), gr.Textbox.update(data["negPrompt"])] + def on_ui_tabs(): with gr.Blocks(analytics_enabled=False) as infinite_zoom_interface: gr.HTML( @@ -309,6 +321,12 @@ def on_ui_tabs(): value=default_negative_prompt, label="Negative Prompt" ) + # these button will be moved using JS unde the dataframe view as small ones + exportPrompts_button= gr.Button(value="Export prompts",variant="secondary",elem_classes="sm infzoom_tab_butt", elem_id="infzoom_exP_butt") + importPrompts_button= gr.UploadButton(value="Import prompts",variant="secondary",elem_classes="sm infzoom_tab_butt", elem_id="infzoom_imP_butt") + exportPrompts_button.click(None,_js="exportPrompts",inputs=[outpaint_prompts,outpaint_negative_prompt],outputs=None) + importPrompts_button.upload(fn=putPrompts,outputs=[outpaint_prompts,outpaint_negative_prompt], inputs=[importPrompts_button]) + outpaint_steps = gr.Slider( minimum=2, maximum=100, diff --git a/style.css b/style.css new file mode 100644 index 0000000..37f8dde --- /dev/null +++ b/style.css @@ -0,0 +1,4 @@ +#tab_iz_interface .gradio-dataframe .controls-wrap { + flex-direction: row-reverse; + justify-content: space-between; +} \ No newline at end of file