Spaces:
Sleeping
Sleeping
update app.py
Browse files
app.py
CHANGED
|
@@ -27,15 +27,15 @@ def infer(
|
|
| 27 |
prompt,
|
| 28 |
negative_prompt,
|
| 29 |
seed,
|
| 30 |
-
randomize_seed,
|
| 31 |
width,
|
| 32 |
height,
|
| 33 |
guidance_scale,
|
| 34 |
num_inference_steps,
|
| 35 |
progress=gr.Progress(track_tqdm=True),
|
| 36 |
):
|
| 37 |
-
if randomize_seed:
|
| 38 |
-
|
| 39 |
|
| 40 |
print(f"Model id: {model_id}")
|
| 41 |
pipe = DiffusionPipeline.from_pretrained(model_id, torch_dtype=torch_dtype)
|
|
@@ -73,6 +73,14 @@ with gr.Blocks(css=css) as demo:
|
|
| 73 |
with gr.Column(elem_id="col-container"):
|
| 74 |
gr.Markdown(" # Text-to-Image Gradio Template")
|
| 75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
prompt = gr.Text(
|
| 77 |
label="Prompt",
|
| 78 |
show_label=False,
|
|
@@ -80,45 +88,43 @@ with gr.Blocks(css=css) as demo:
|
|
| 80 |
placeholder="Enter your prompt",
|
| 81 |
container=False,
|
| 82 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
with gr.Row():
|
| 85 |
-
model_id = gr.Text(
|
| 86 |
-
label="Model ID",
|
| 87 |
-
show_label=False,
|
| 88 |
-
max_lines=1,
|
| 89 |
-
placeholder="Enter model id",
|
| 90 |
-
container=False,
|
| 91 |
-
value="CompVis/stable-diffusion-v1-4",
|
| 92 |
-
)
|
| 93 |
-
# prompt = gr.Text(
|
| 94 |
-
# label="Prompt",
|
| 95 |
-
# show_label=False,
|
| 96 |
-
# max_lines=1,
|
| 97 |
-
# placeholder="Enter your prompt",
|
| 98 |
-
# container=False,
|
| 99 |
-
# )
|
| 100 |
-
|
| 101 |
-
run_button = gr.Button("Run", scale=0, variant="primary")
|
| 102 |
-
|
| 103 |
-
result = gr.Image(label="Result", show_label=False)
|
| 104 |
-
|
| 105 |
-
with gr.Accordion("Advanced Settings", open=False):
|
| 106 |
-
negative_prompt = gr.Text(
|
| 107 |
-
label="Negative prompt",
|
| 108 |
-
max_lines=1,
|
| 109 |
-
placeholder="Enter a negative prompt",
|
| 110 |
-
visible=False,
|
| 111 |
-
)
|
| 112 |
-
|
| 113 |
seed = gr.Slider(
|
| 114 |
label="Seed",
|
| 115 |
minimum=0,
|
| 116 |
maximum=MAX_SEED,
|
| 117 |
step=1,
|
| 118 |
-
value=
|
| 119 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
|
| 121 |
-
|
|
|
|
|
|
|
| 122 |
|
| 123 |
with gr.Row():
|
| 124 |
width = gr.Slider(
|
|
@@ -137,22 +143,6 @@ with gr.Blocks(css=css) as demo:
|
|
| 137 |
value=1024, # Replace with defaults that work for your model
|
| 138 |
)
|
| 139 |
|
| 140 |
-
with gr.Row():
|
| 141 |
-
guidance_scale = gr.Slider(
|
| 142 |
-
label="Guidance scale",
|
| 143 |
-
minimum=0.0,
|
| 144 |
-
maximum=10.0,
|
| 145 |
-
step=0.1,
|
| 146 |
-
value=0.0, # Replace with defaults that work for your model
|
| 147 |
-
)
|
| 148 |
-
|
| 149 |
-
num_inference_steps = gr.Slider(
|
| 150 |
-
label="Number of inference steps",
|
| 151 |
-
minimum=1,
|
| 152 |
-
maximum=50,
|
| 153 |
-
step=1,
|
| 154 |
-
value=2, # Replace with defaults that work for your model
|
| 155 |
-
)
|
| 156 |
|
| 157 |
gr.Examples(examples=examples, inputs=[prompt])
|
| 158 |
gr.on(
|
|
@@ -163,7 +153,6 @@ with gr.Blocks(css=css) as demo:
|
|
| 163 |
prompt,
|
| 164 |
negative_prompt,
|
| 165 |
seed,
|
| 166 |
-
randomize_seed,
|
| 167 |
width,
|
| 168 |
height,
|
| 169 |
guidance_scale,
|
|
|
|
| 27 |
prompt,
|
| 28 |
negative_prompt,
|
| 29 |
seed,
|
| 30 |
+
# randomize_seed,
|
| 31 |
width,
|
| 32 |
height,
|
| 33 |
guidance_scale,
|
| 34 |
num_inference_steps,
|
| 35 |
progress=gr.Progress(track_tqdm=True),
|
| 36 |
):
|
| 37 |
+
# if randomize_seed:
|
| 38 |
+
# seed = random.randint(0, MAX_SEED)
|
| 39 |
|
| 40 |
print(f"Model id: {model_id}")
|
| 41 |
pipe = DiffusionPipeline.from_pretrained(model_id, torch_dtype=torch_dtype)
|
|
|
|
| 73 |
with gr.Column(elem_id="col-container"):
|
| 74 |
gr.Markdown(" # Text-to-Image Gradio Template")
|
| 75 |
|
| 76 |
+
model_id = gr.Text(
|
| 77 |
+
label="Model ID",
|
| 78 |
+
show_label=False,
|
| 79 |
+
max_lines=1,
|
| 80 |
+
placeholder="Enter model id",
|
| 81 |
+
container=False,
|
| 82 |
+
value="CompVis/stable-diffusion-v1-4",
|
| 83 |
+
)
|
| 84 |
prompt = gr.Text(
|
| 85 |
label="Prompt",
|
| 86 |
show_label=False,
|
|
|
|
| 88 |
placeholder="Enter your prompt",
|
| 89 |
container=False,
|
| 90 |
)
|
| 91 |
+
negative_prompt = gr.Text(
|
| 92 |
+
label="Negative prompt",
|
| 93 |
+
max_lines=1,
|
| 94 |
+
placeholder="Enter a negative prompt",
|
| 95 |
+
visible=False,
|
| 96 |
+
)
|
| 97 |
|
| 98 |
with gr.Row():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
seed = gr.Slider(
|
| 100 |
label="Seed",
|
| 101 |
minimum=0,
|
| 102 |
maximum=MAX_SEED,
|
| 103 |
step=1,
|
| 104 |
+
value=42,
|
| 105 |
)
|
| 106 |
+
guidance_scale = gr.Slider(
|
| 107 |
+
label="Guidance scale",
|
| 108 |
+
minimum=0.0,
|
| 109 |
+
maximum=10.0,
|
| 110 |
+
step=0.1,
|
| 111 |
+
value=7.0, # Replace with defaults that work for your model
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
with gr.Row():
|
| 116 |
+
num_inference_steps = gr.Slider(
|
| 117 |
+
label="Number of inference steps",
|
| 118 |
+
minimum=1,
|
| 119 |
+
maximum=50,
|
| 120 |
+
step=1,
|
| 121 |
+
value=20, # Replace with defaults that work for your model
|
| 122 |
+
)
|
| 123 |
+
run_button = gr.Button("Run", scale=0, variant="primary")
|
| 124 |
|
| 125 |
+
result = gr.Image(label="Result", show_label=False)
|
| 126 |
+
|
| 127 |
+
with gr.Accordion("Advanced Settings", open=False):
|
| 128 |
|
| 129 |
with gr.Row():
|
| 130 |
width = gr.Slider(
|
|
|
|
| 143 |
value=1024, # Replace with defaults that work for your model
|
| 144 |
)
|
| 145 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
|
| 147 |
gr.Examples(examples=examples, inputs=[prompt])
|
| 148 |
gr.on(
|
|
|
|
| 153 |
prompt,
|
| 154 |
negative_prompt,
|
| 155 |
seed,
|
|
|
|
| 156 |
width,
|
| 157 |
height,
|
| 158 |
guidance_scale,
|