Spaces:
Runtime error
Runtime error
final fix for the gallery, change endpoint to SDXL 1.0
Browse files
app.py
CHANGED
|
@@ -15,13 +15,13 @@ USERNAME = os.getenv("USERNAME")
|
|
| 15 |
PASS = os.getenv("PASS")
|
| 16 |
|
| 17 |
# set up dataset writer
|
| 18 |
-
hf_writer_gen = gr.HuggingFaceDatasetSaver(HF_KEY, "helms/master-thesis-generated-images
|
| 19 |
|
| 20 |
def infer(prompt):
|
| 21 |
stability_api = client.StabilityInference(
|
| 22 |
key=SD_KEY, # AaPI Key reference.
|
| 23 |
verbose=True, # Print debug messages.
|
| 24 |
-
engine="stable-diffusion-v1", # Set the engine to use for generation.
|
| 25 |
# Available engines: stable-diffusion-xl-1024-v1-0 stable-diffusion-xl-1024-v0-9 stable-diffusion-v1 stable-diffusion-v1-5 stable-diffusion-512-v2-0 stable-diffusion-768-v2-0
|
| 26 |
# stable-diffusion-512-v2-1 stable-diffusion-768-v2-1 stable-diffusion-xl-beta-v2-2-2 stable-inpainting-v1-0 stable-inpainting-512-v2-0
|
| 27 |
)
|
|
@@ -34,8 +34,8 @@ def infer(prompt):
|
|
| 34 |
cfg_scale=7.0, # Influences how strongly your generation is guided to match your prompt.
|
| 35 |
# Setting this value higher increases the strength in which it tries to match your prompt.
|
| 36 |
# Defaults to 7.0 if not specified.
|
| 37 |
-
width=
|
| 38 |
-
height=
|
| 39 |
samples=1, # Number of images to generate, defaults to 1 if not included.
|
| 40 |
sampler=generation.SAMPLER_K_DPMPP_2M # Choose which sampler we want to denoise our generation with.
|
| 41 |
# Defaults to k_dpmpp_2m if not specified. Clip Guidance only supports ancestral samplers.
|
|
@@ -55,7 +55,6 @@ def infer(prompt):
|
|
| 55 |
|
| 56 |
|
| 57 |
with gr.Blocks(title="Master Thesis Image Generator") as demo:
|
| 58 |
-
storage = gr.State(value=[])
|
| 59 |
with gr.Row():
|
| 60 |
gr.HTML("""
|
| 61 |
<div style="text-align: justify; margin: 0 auto;">
|
|
@@ -85,8 +84,7 @@ with gr.Blocks(title="Master Thesis Image Generator") as demo:
|
|
| 85 |
with gr.Box():
|
| 86 |
gr.HTML(
|
| 87 |
"""<div style="text-align: center; margin: 0 auto; padding-bottom: 10px"><p style="font-size:10pt">Generated Images</p></div>""")
|
| 88 |
-
store = gr.Gallery(value=
|
| 89 |
-
gr.ClearButton(store)
|
| 90 |
with gr.Column(scale=3):
|
| 91 |
out = gr.Image(interactive=False, visible=True, container=True, width=1024, show_share_button=False)
|
| 92 |
with gr.Row():
|
|
@@ -111,14 +109,8 @@ with gr.Blocks(title="Master Thesis Image Generator") as demo:
|
|
| 111 |
def make_active():
|
| 112 |
return gr.update(interactive=True)
|
| 113 |
|
| 114 |
-
def add_to_gallery(img):
|
| 115 |
-
|
| 116 |
-
gall.insert(0, img)
|
| 117 |
-
return gall
|
| 118 |
-
|
| 119 |
-
def clear_gallery():
|
| 120 |
-
gall = []
|
| 121 |
-
return gall, gall
|
| 122 |
|
| 123 |
def select_img(evt: gr.SelectData):
|
| 124 |
sel_img = store.value[evt.index]
|
|
@@ -129,19 +121,17 @@ with gr.Blocks(title="Master Thesis Image Generator") as demo:
|
|
| 129 |
btn_gen.click(
|
| 130 |
fn=make_inactive, outputs=btn_gen).then(
|
| 131 |
fn=infer, inputs=inp, outputs=out, scroll_to_output=True).then(
|
| 132 |
-
fn=add_to_gallery, inputs=out, outputs=store).then(
|
| 133 |
fn=make_active, outputs=btn_gen).then(
|
| 134 |
lambda *args: hf_writer_gen.flag(args), inputs=[user, inp, out], outputs=None, preprocess=False)
|
| 135 |
|
| 136 |
inp.submit(
|
| 137 |
fn=make_inactive, outputs=btn_gen).then(
|
| 138 |
fn=infer, inputs=inp, outputs=out, scroll_to_output=True).then(
|
| 139 |
-
fn=add_to_gallery, inputs=out, outputs=store).then(
|
| 140 |
fn=make_active, outputs=btn_gen).then(
|
| 141 |
lambda *args: hf_writer_gen.flag(args), inputs=[user, inp, out], outputs=None, preprocess=False)
|
| 142 |
|
| 143 |
store.select(fn=select_img, outputs=out)
|
| 144 |
|
| 145 |
-
demo.load(fn=clear_gallery, outputs=[store, storage], api_name=False)
|
| 146 |
-
|
| 147 |
demo.launch(show_api=False, auth=(USERNAME, PASS))
|
|
|
|
| 15 |
PASS = os.getenv("PASS")
|
| 16 |
|
| 17 |
# set up dataset writer
|
| 18 |
+
hf_writer_gen = gr.HuggingFaceDatasetSaver(HF_KEY, "helms/master-thesis-generated-images", private=True, separate_dirs=False)
|
| 19 |
|
| 20 |
def infer(prompt):
|
| 21 |
stability_api = client.StabilityInference(
|
| 22 |
key=SD_KEY, # AaPI Key reference.
|
| 23 |
verbose=True, # Print debug messages.
|
| 24 |
+
engine="stable-diffusion-xl-1024-v1-0", # Set the engine to use for generation.
|
| 25 |
# Available engines: stable-diffusion-xl-1024-v1-0 stable-diffusion-xl-1024-v0-9 stable-diffusion-v1 stable-diffusion-v1-5 stable-diffusion-512-v2-0 stable-diffusion-768-v2-0
|
| 26 |
# stable-diffusion-512-v2-1 stable-diffusion-768-v2-1 stable-diffusion-xl-beta-v2-2-2 stable-inpainting-v1-0 stable-inpainting-512-v2-0
|
| 27 |
)
|
|
|
|
| 34 |
cfg_scale=7.0, # Influences how strongly your generation is guided to match your prompt.
|
| 35 |
# Setting this value higher increases the strength in which it tries to match your prompt.
|
| 36 |
# Defaults to 7.0 if not specified.
|
| 37 |
+
width=1024, # Generation width, defaults to 512 if not included.
|
| 38 |
+
height=1024, # Generation height, defaults to 512 if not included.
|
| 39 |
samples=1, # Number of images to generate, defaults to 1 if not included.
|
| 40 |
sampler=generation.SAMPLER_K_DPMPP_2M # Choose which sampler we want to denoise our generation with.
|
| 41 |
# Defaults to k_dpmpp_2m if not specified. Clip Guidance only supports ancestral samplers.
|
|
|
|
| 55 |
|
| 56 |
|
| 57 |
with gr.Blocks(title="Master Thesis Image Generator") as demo:
|
|
|
|
| 58 |
with gr.Row():
|
| 59 |
gr.HTML("""
|
| 60 |
<div style="text-align: justify; margin: 0 auto;">
|
|
|
|
| 84 |
with gr.Box():
|
| 85 |
gr.HTML(
|
| 86 |
"""<div style="text-align: center; margin: 0 auto; padding-bottom: 10px"><p style="font-size:10pt">Generated Images</p></div>""")
|
| 87 |
+
store = gr.Gallery(value=[], visible=True, show_share_button=False, allow_preview=False, columns=1)
|
|
|
|
| 88 |
with gr.Column(scale=3):
|
| 89 |
out = gr.Image(interactive=False, visible=True, container=True, width=1024, show_share_button=False)
|
| 90 |
with gr.Row():
|
|
|
|
| 109 |
def make_active():
|
| 110 |
return gr.update(interactive=True)
|
| 111 |
|
| 112 |
+
def add_to_gallery(img, gall):
|
| 113 |
+
return [img] + [d['name'] for d in gall]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
def select_img(evt: gr.SelectData):
|
| 116 |
sel_img = store.value[evt.index]
|
|
|
|
| 121 |
btn_gen.click(
|
| 122 |
fn=make_inactive, outputs=btn_gen).then(
|
| 123 |
fn=infer, inputs=inp, outputs=out, scroll_to_output=True).then(
|
| 124 |
+
fn=add_to_gallery, inputs=[out, store], outputs=store).then(
|
| 125 |
fn=make_active, outputs=btn_gen).then(
|
| 126 |
lambda *args: hf_writer_gen.flag(args), inputs=[user, inp, out], outputs=None, preprocess=False)
|
| 127 |
|
| 128 |
inp.submit(
|
| 129 |
fn=make_inactive, outputs=btn_gen).then(
|
| 130 |
fn=infer, inputs=inp, outputs=out, scroll_to_output=True).then(
|
| 131 |
+
fn=add_to_gallery, inputs=[out, store], outputs=store).then(
|
| 132 |
fn=make_active, outputs=btn_gen).then(
|
| 133 |
lambda *args: hf_writer_gen.flag(args), inputs=[user, inp, out], outputs=None, preprocess=False)
|
| 134 |
|
| 135 |
store.select(fn=select_img, outputs=out)
|
| 136 |
|
|
|
|
|
|
|
| 137 |
demo.launch(show_api=False, auth=(USERNAME, PASS))
|