Alexander Hux commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,7 +11,7 @@ if torch.cuda.is_available():
|
|
| 11 |
pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
|
| 12 |
pipe.enable_xformers_memory_efficient_attention()
|
| 13 |
pipe = pipe.to(device)
|
| 14 |
-
else:
|
| 15 |
pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", use_safetensors=True)
|
| 16 |
pipe = pipe.to(device)
|
| 17 |
|
|
@@ -19,27 +19,26 @@ MAX_SEED = np.iinfo(np.int32).max
|
|
| 19 |
MAX_IMAGE_SIZE = 1024
|
| 20 |
|
| 21 |
def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
|
| 22 |
-
|
| 23 |
if randomize_seed:
|
| 24 |
seed = random.randint(0, MAX_SEED)
|
| 25 |
|
| 26 |
generator = torch.Generator().manual_seed(seed)
|
| 27 |
|
| 28 |
image = pipe(
|
| 29 |
-
prompt
|
| 30 |
-
negative_prompt
|
| 31 |
-
guidance_scale
|
| 32 |
-
num_inference_steps
|
| 33 |
-
width
|
| 34 |
-
height
|
| 35 |
-
generator
|
| 36 |
).images[0]
|
| 37 |
|
| 38 |
return image
|
| 39 |
|
| 40 |
examples = [
|
| 41 |
"Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
|
| 42 |
-
"A Chrome wrapped Chevy
|
| 43 |
"A delicious ceviche cheesecake slice",
|
| 44 |
]
|
| 45 |
|
|
@@ -61,11 +60,9 @@ else:
|
|
| 61 |
power_device = "CPU"
|
| 62 |
|
| 63 |
with gr.Blocks(css=css) as demo:
|
| 64 |
-
with gr.HTML("""
|
| 65 |
-
<button id="connect-wallet" style="background-color: #4CAF50; border: none; color: white; padding: 10px 20px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; margin: 4px 2px; cursor: pointer; border-radius: 8px;">Connect Wallet</button>
|
| 66 |
-
"""):
|
| 67 |
-
pass
|
| 68 |
|
|
|
|
|
|
|
| 69 |
with gr.Column(elem_id="col-container"):
|
| 70 |
gr.Markdown(f"""
|
| 71 |
# Open Image - Open Source Txt2Img
|
|
@@ -74,7 +71,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 74 |
|
| 75 |
with gr.Row():
|
| 76 |
|
| 77 |
-
prompt = gr.
|
| 78 |
label="Prompt",
|
| 79 |
show_label=False,
|
| 80 |
max_lines=1,
|
|
@@ -87,5 +84,33 @@ with gr.Blocks(css=css) as demo:
|
|
| 87 |
result = gr.Image(label="Result", show_label=False)
|
| 88 |
|
| 89 |
with gr.Accordion("Advanced Settings", open=False):
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
|
| 12 |
pipe.enable_xformers_memory_efficient_attention()
|
| 13 |
pipe = pipe.to(device)
|
| 14 |
+
else:
|
| 15 |
pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", use_safetensors=True)
|
| 16 |
pipe = pipe.to(device)
|
| 17 |
|
|
|
|
| 19 |
MAX_IMAGE_SIZE = 1024
|
| 20 |
|
| 21 |
def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
|
|
|
|
| 22 |
if randomize_seed:
|
| 23 |
seed = random.randint(0, MAX_SEED)
|
| 24 |
|
| 25 |
generator = torch.Generator().manual_seed(seed)
|
| 26 |
|
| 27 |
image = pipe(
|
| 28 |
+
prompt=prompt,
|
| 29 |
+
negative_prompt=negative_prompt,
|
| 30 |
+
guidance_scale=guidance_scale,
|
| 31 |
+
num_inference_steps=num_inference_steps,
|
| 32 |
+
width=width,
|
| 33 |
+
height=height,
|
| 34 |
+
generator=generator
|
| 35 |
).images[0]
|
| 36 |
|
| 37 |
return image
|
| 38 |
|
| 39 |
examples = [
|
| 40 |
"Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
|
| 41 |
+
"A Chrome wrapped Chevy Camaro in the desert with neon blue underglow",
|
| 42 |
"A delicious ceviche cheesecake slice",
|
| 43 |
]
|
| 44 |
|
|
|
|
| 60 |
power_device = "CPU"
|
| 61 |
|
| 62 |
with gr.Blocks(css=css) as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
+
connect_wallet_button = gr.Button("Connect Wallet", elem_id="connect-wallet")
|
| 65 |
+
|
| 66 |
with gr.Column(elem_id="col-container"):
|
| 67 |
gr.Markdown(f"""
|
| 68 |
# Open Image - Open Source Txt2Img
|
|
|
|
| 71 |
|
| 72 |
with gr.Row():
|
| 73 |
|
| 74 |
+
prompt = gr.Textbox(
|
| 75 |
label="Prompt",
|
| 76 |
show_label=False,
|
| 77 |
max_lines=1,
|
|
|
|
| 84 |
result = gr.Image(label="Result", show_label=False)
|
| 85 |
|
| 86 |
with gr.Accordion("Advanced Settings", open=False):
|
| 87 |
+
negative_prompt = gr.Textbox(
|
| 88 |
+
label="Negative Prompt",
|
| 89 |
+
show_label=True,
|
| 90 |
+
placeholder="Enter negative prompt"
|
| 91 |
+
)
|
| 92 |
+
seed = gr.Slider(0, MAX_SEED, value=0, step=1, label="Seed", show_label=True)
|
| 93 |
+
randomize_seed = gr.Checkbox(label="Randomize Seed", value=True)
|
| 94 |
+
width = gr.Slider(64, MAX_IMAGE_SIZE, value=512, step=64, label="Width")
|
| 95 |
+
height = gr.Slider(64, MAX_IMAGE_SIZE, value=512, step=64, label="Height")
|
| 96 |
+
guidance_scale = gr.Slider(1, 20, value=7.5, step=0.1, label="Guidance Scale")
|
| 97 |
+
num_inference_steps = gr.Slider(1, 100, value=50, step=1, label="Inference Steps")
|
| 98 |
+
|
| 99 |
+
run_button.click(
|
| 100 |
+
infer,
|
| 101 |
+
inputs=[
|
| 102 |
+
prompt,
|
| 103 |
+
negative_prompt,
|
| 104 |
+
seed,
|
| 105 |
+
randomize_seed,
|
| 106 |
+
width,
|
| 107 |
+
height,
|
| 108 |
+
guidance_scale,
|
| 109 |
+
num_inference_steps
|
| 110 |
+
],
|
| 111 |
+
outputs=result
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
gr.Examples(examples, [prompt], result, fn=infer)
|
| 115 |
+
|
| 116 |
+
demo.launch()
|