Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,18 +23,22 @@ MAX_IMAGE_SIZE = 1024
|
|
| 23 |
|
| 24 |
# @spaces.GPU #[uncomment to use ZeroGPU]
|
| 25 |
def infer(
|
|
|
|
| 26 |
prompt,
|
| 27 |
negative_prompt,
|
| 28 |
seed,
|
| 29 |
-
randomize_seed,
|
| 30 |
width,
|
| 31 |
height,
|
| 32 |
guidance_scale,
|
| 33 |
num_inference_steps,
|
| 34 |
progress=gr.Progress(track_tqdm=True),
|
| 35 |
):
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
generator = torch.Generator().manual_seed(seed)
|
| 40 |
|
|
@@ -52,9 +56,10 @@ def infer(
|
|
| 52 |
|
| 53 |
|
| 54 |
examples = [
|
| 55 |
-
"Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
|
| 56 |
-
"An astronaut riding a green horse",
|
| 57 |
-
"A delicious ceviche cheesecake slice",
|
|
|
|
| 58 |
]
|
| 59 |
|
| 60 |
css = """
|
|
@@ -64,40 +69,67 @@ css = """
|
|
| 64 |
}
|
| 65 |
"""
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
|
|
|
|
|
|
| 70 |
|
| 71 |
-
|
| 72 |
-
prompt = gr.Text(
|
| 73 |
-
label="Prompt",
|
| 74 |
-
show_label=False,
|
| 75 |
-
max_lines=1,
|
| 76 |
-
placeholder="Enter your prompt",
|
| 77 |
-
container=False,
|
| 78 |
-
)
|
| 79 |
|
| 80 |
-
|
| 81 |
|
| 82 |
-
|
|
|
|
| 83 |
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
label="Seed",
|
| 94 |
minimum=0,
|
| 95 |
maximum=MAX_SEED,
|
| 96 |
step=1,
|
| 97 |
value=0,
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
with gr.Row():
|
| 103 |
width = gr.Slider(
|
|
@@ -116,23 +148,6 @@ with gr.Blocks(css=css) as demo:
|
|
| 116 |
value=1024, # Replace with defaults that work for your model
|
| 117 |
)
|
| 118 |
|
| 119 |
-
with gr.Row():
|
| 120 |
-
guidance_scale = gr.Slider(
|
| 121 |
-
label="Guidance scale",
|
| 122 |
-
minimum=0.0,
|
| 123 |
-
maximum=10.0,
|
| 124 |
-
step=0.1,
|
| 125 |
-
value=0.0, # Replace with defaults that work for your model
|
| 126 |
-
)
|
| 127 |
-
|
| 128 |
-
num_inference_steps = gr.Slider(
|
| 129 |
-
label="Number of inference steps",
|
| 130 |
-
minimum=1,
|
| 131 |
-
maximum=50,
|
| 132 |
-
step=1,
|
| 133 |
-
value=2, # Replace with defaults that work for your model
|
| 134 |
-
)
|
| 135 |
-
|
| 136 |
gr.Examples(examples=examples, inputs=[prompt])
|
| 137 |
gr.on(
|
| 138 |
triggers=[run_button.click, prompt.submit],
|
|
@@ -152,3 +167,4 @@ with gr.Blocks(css=css) as demo:
|
|
| 152 |
|
| 153 |
if __name__ == "__main__":
|
| 154 |
demo.launch()
|
|
|
|
|
|
| 23 |
|
| 24 |
# @spaces.GPU #[uncomment to use ZeroGPU]
|
| 25 |
def infer(
|
| 26 |
+
model,
|
| 27 |
prompt,
|
| 28 |
negative_prompt,
|
| 29 |
seed,
|
|
|
|
| 30 |
width,
|
| 31 |
height,
|
| 32 |
guidance_scale,
|
| 33 |
num_inference_steps,
|
| 34 |
progress=gr.Progress(track_tqdm=True),
|
| 35 |
):
|
| 36 |
+
|
| 37 |
+
global model_repo_id
|
| 38 |
+
if model != model_repo_id:
|
| 39 |
+
print(model, model_repo_id)
|
| 40 |
+
pipe = DiffusionPipeline.from_pretrained(model, torch_dtype=torch_dtype)
|
| 41 |
+
pipe = pipe.to(device)
|
| 42 |
|
| 43 |
generator = torch.Generator().manual_seed(seed)
|
| 44 |
|
|
|
|
| 56 |
|
| 57 |
|
| 58 |
examples = [
|
| 59 |
+
"Astronaut in a jungle, cold color palette, muted colors, detailed, 8k.",
|
| 60 |
+
"An astronaut riding a green horse.",
|
| 61 |
+
"A delicious ceviche cheesecake slice.",
|
| 62 |
+
"A futuristic sports car is located on the surface of Mars. Stars, planets, mountains and craters are visible.",
|
| 63 |
]
|
| 64 |
|
| 65 |
css = """
|
|
|
|
| 69 |
}
|
| 70 |
"""
|
| 71 |
|
| 72 |
+
available_models = [
|
| 73 |
+
"CompVis/stable-diffusion-v1-4",
|
| 74 |
+
"stabilityai/sdxl-turbo",
|
| 75 |
+
"runwayml/stable-diffusion-v1-5",
|
| 76 |
+
"prompthero/openjourney"
|
| 77 |
|
| 78 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
+
with gr.Blocks(css=css) as demo:
|
| 81 |
|
| 82 |
+
with gr.Column(elem_id="col-container"):
|
| 83 |
+
gr.Markdown(" # Text-to-Image Gradio Template from V. Gorsky")
|
| 84 |
|
| 85 |
+
model = gr.Dropdown(
|
| 86 |
+
label="Model Selection",
|
| 87 |
+
choices=available_models,
|
| 88 |
+
value="CompVis/stable-diffusion-v1-4",
|
| 89 |
+
interactive=True
|
| 90 |
+
)
|
| 91 |
+
prompt = gr.Text(
|
| 92 |
+
label="Prompt",
|
| 93 |
+
show_label=False,
|
| 94 |
+
max_lines=1,
|
| 95 |
+
placeholder="Enter your prompt",
|
| 96 |
+
container=False,
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
negative_prompt = gr.Text(
|
| 100 |
+
label="Negative prompt",
|
| 101 |
+
max_lines=1,
|
| 102 |
+
placeholder="Enter a negative prompt",
|
| 103 |
+
visible=True,
|
| 104 |
+
)
|
| 105 |
+
seed = gr.Slider(
|
| 106 |
label="Seed",
|
| 107 |
minimum=0,
|
| 108 |
maximum=MAX_SEED,
|
| 109 |
step=1,
|
| 110 |
value=0,
|
| 111 |
+
)
|
| 112 |
+
guidance_scale = gr.Slider(
|
| 113 |
+
label="Guidance scale",
|
| 114 |
+
minimum=0.0,
|
| 115 |
+
maximum=10.0,
|
| 116 |
+
step=0.1,
|
| 117 |
+
value=7.0, # Replace with defaults that work for your model
|
| 118 |
+
)
|
| 119 |
+
|
| 120 |
+
num_inference_steps = gr.Slider(
|
| 121 |
+
label="Number of inference steps",
|
| 122 |
+
minimum=1,
|
| 123 |
+
maximum=50,
|
| 124 |
+
step=1,
|
| 125 |
+
value=20, # Replace with defaults that work for your model
|
| 126 |
+
)
|
| 127 |
|
| 128 |
+
run_button = gr.Button("Run", scale=0, variant="primary")
|
| 129 |
+
|
| 130 |
+
result = gr.Image(label="Result", show_label=False)
|
| 131 |
+
|
| 132 |
+
with gr.Accordion("Advanced Settings", open=False):
|
| 133 |
|
| 134 |
with gr.Row():
|
| 135 |
width = gr.Slider(
|
|
|
|
| 148 |
value=1024, # Replace with defaults that work for your model
|
| 149 |
)
|
| 150 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
gr.Examples(examples=examples, inputs=[prompt])
|
| 152 |
gr.on(
|
| 153 |
triggers=[run_button.click, prompt.submit],
|
|
|
|
| 167 |
|
| 168 |
if __name__ == "__main__":
|
| 169 |
demo.launch()
|
| 170 |
+
|