UM
commited on
Commit
·
2717395
1
Parent(s):
eae2af0
first
Browse files
app.py
CHANGED
|
@@ -23,6 +23,7 @@ MAX_IMAGE_SIZE = 1024
|
|
| 23 |
|
| 24 |
# @spaces.GPU #[uncomment to use ZeroGPU]
|
| 25 |
def infer(
|
|
|
|
| 26 |
prompt,
|
| 27 |
negative_prompt,
|
| 28 |
seed,
|
|
@@ -37,6 +38,9 @@ def infer(
|
|
| 37 |
seed = random.randint(0, MAX_SEED)
|
| 38 |
|
| 39 |
generator = torch.Generator().manual_seed(seed)
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
image = pipe(
|
| 42 |
prompt=prompt,
|
|
@@ -67,7 +71,16 @@ css = """
|
|
| 67 |
with gr.Blocks(css=css) as demo:
|
| 68 |
with gr.Column(elem_id="col-container"):
|
| 69 |
gr.Markdown(" # Text-to-Image Gradio Template")
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
with gr.Row():
|
| 72 |
prompt = gr.Text(
|
| 73 |
label="Prompt",
|
|
@@ -94,7 +107,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 94 |
minimum=0,
|
| 95 |
maximum=MAX_SEED,
|
| 96 |
step=1,
|
| 97 |
-
value=
|
| 98 |
)
|
| 99 |
|
| 100 |
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
|
@@ -122,7 +135,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 122 |
minimum=0.0,
|
| 123 |
maximum=10.0,
|
| 124 |
step=0.1,
|
| 125 |
-
value=
|
| 126 |
)
|
| 127 |
|
| 128 |
num_inference_steps = gr.Slider(
|
|
@@ -130,7 +143,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 130 |
minimum=1,
|
| 131 |
maximum=50,
|
| 132 |
step=1,
|
| 133 |
-
value=
|
| 134 |
)
|
| 135 |
|
| 136 |
gr.Examples(examples=examples, inputs=[prompt])
|
|
@@ -138,6 +151,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 138 |
triggers=[run_button.click, prompt.submit],
|
| 139 |
fn=infer,
|
| 140 |
inputs=[
|
|
|
|
| 141 |
prompt,
|
| 142 |
negative_prompt,
|
| 143 |
seed,
|
|
|
|
| 23 |
|
| 24 |
# @spaces.GPU #[uncomment to use ZeroGPU]
|
| 25 |
def infer(
|
| 26 |
+
model_id,
|
| 27 |
prompt,
|
| 28 |
negative_prompt,
|
| 29 |
seed,
|
|
|
|
| 38 |
seed = random.randint(0, MAX_SEED)
|
| 39 |
|
| 40 |
generator = torch.Generator().manual_seed(seed)
|
| 41 |
+
|
| 42 |
+
pipe = DiffusionPipeline.from_pretrained(model_id, torch_dtype=torch_dtype)
|
| 43 |
+
pipe = pipe.to(device)
|
| 44 |
|
| 45 |
image = pipe(
|
| 46 |
prompt=prompt,
|
|
|
|
| 71 |
with gr.Blocks(css=css) as demo:
|
| 72 |
with gr.Column(elem_id="col-container"):
|
| 73 |
gr.Markdown(" # Text-to-Image Gradio Template")
|
| 74 |
+
|
| 75 |
+
model_id_input = gr.Text(
|
| 76 |
+
label="Enter Model ID",
|
| 77 |
+
value="CompVis/stable-diffusion-v1-4",
|
| 78 |
+
show_label=True,
|
| 79 |
+
placeholder="Enter model",
|
| 80 |
+
)
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
|
| 84 |
with gr.Row():
|
| 85 |
prompt = gr.Text(
|
| 86 |
label="Prompt",
|
|
|
|
| 107 |
minimum=0,
|
| 108 |
maximum=MAX_SEED,
|
| 109 |
step=1,
|
| 110 |
+
value=42,
|
| 111 |
)
|
| 112 |
|
| 113 |
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
|
|
|
| 135 |
minimum=0.0,
|
| 136 |
maximum=10.0,
|
| 137 |
step=0.1,
|
| 138 |
+
value=7.0, # Replace with defaults that work for your model
|
| 139 |
)
|
| 140 |
|
| 141 |
num_inference_steps = gr.Slider(
|
|
|
|
| 143 |
minimum=1,
|
| 144 |
maximum=50,
|
| 145 |
step=1,
|
| 146 |
+
value=20, # Replace with defaults that work for your model
|
| 147 |
)
|
| 148 |
|
| 149 |
gr.Examples(examples=examples, inputs=[prompt])
|
|
|
|
| 151 |
triggers=[run_button.click, prompt.submit],
|
| 152 |
fn=infer,
|
| 153 |
inputs=[
|
| 154 |
+
model_id_input,
|
| 155 |
prompt,
|
| 156 |
negative_prompt,
|
| 157 |
seed,
|