Spaces:
Sleeping
Sleeping
update app.py
Browse files
app.py
CHANGED
|
@@ -7,15 +7,15 @@ from diffusers import DiffusionPipeline
|
|
| 7 |
import torch
|
| 8 |
|
| 9 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 10 |
-
model_repo_id = "stabilityai/sdxl-turbo" # Replace to the model you would like to use
|
| 11 |
|
| 12 |
if torch.cuda.is_available():
|
| 13 |
torch_dtype = torch.float16
|
| 14 |
else:
|
| 15 |
torch_dtype = torch.float32
|
| 16 |
|
| 17 |
-
pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
|
| 18 |
-
pipe = pipe.to(device)
|
| 19 |
|
| 20 |
MAX_SEED = np.iinfo(np.int32).max
|
| 21 |
MAX_IMAGE_SIZE = 1024
|
|
@@ -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,
|
|
@@ -36,6 +37,10 @@ def infer(
|
|
| 36 |
if randomize_seed:
|
| 37 |
seed = random.randint(0, MAX_SEED)
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
generator = torch.Generator().manual_seed(seed)
|
| 40 |
|
| 41 |
image = pipe(
|
|
@@ -68,14 +73,30 @@ 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 |
-
|
| 73 |
-
label="
|
| 74 |
show_label=False,
|
| 75 |
max_lines=1,
|
| 76 |
-
placeholder="Enter
|
| 77 |
container=False,
|
|
|
|
| 78 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
run_button = gr.Button("Run", scale=0, variant="primary")
|
| 81 |
|
|
@@ -138,6 +159,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,
|
|
|
|
| 7 |
import torch
|
| 8 |
|
| 9 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 10 |
+
# model_repo_id = "stabilityai/sdxl-turbo" # Replace to the model you would like to use
|
| 11 |
|
| 12 |
if torch.cuda.is_available():
|
| 13 |
torch_dtype = torch.float16
|
| 14 |
else:
|
| 15 |
torch_dtype = torch.float32
|
| 16 |
|
| 17 |
+
# pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
|
| 18 |
+
# pipe = pipe.to(device)
|
| 19 |
|
| 20 |
MAX_SEED = np.iinfo(np.int32).max
|
| 21 |
MAX_IMAGE_SIZE = 1024
|
|
|
|
| 23 |
|
| 24 |
# @spaces.GPU #[uncomment to use ZeroGPU]
|
| 25 |
def infer(
|
| 26 |
+
model_id,
|
| 27 |
prompt,
|
| 28 |
negative_prompt,
|
| 29 |
seed,
|
|
|
|
| 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)
|
| 42 |
+
pipe = pipe.to(device)
|
| 43 |
+
|
| 44 |
generator = torch.Generator().manual_seed(seed)
|
| 45 |
|
| 46 |
image = pipe(
|
|
|
|
| 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,
|
| 79 |
+
max_lines=1,
|
| 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 |
|
|
|
|
| 159 |
triggers=[run_button.click, prompt.submit],
|
| 160 |
fn=infer,
|
| 161 |
inputs=[
|
| 162 |
+
model_id,
|
| 163 |
prompt,
|
| 164 |
negative_prompt,
|
| 165 |
seed,
|