Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,13 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import numpy as np
|
| 3 |
import random
|
|
|
|
|
|
|
| 4 |
from diffusers import DiffusionPipeline
|
| 5 |
import torch
|
| 6 |
|
| 7 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 8 |
-
model_repo_id = "stabilityai/sdxl-turbo"
|
| 9 |
|
| 10 |
if torch.cuda.is_available():
|
| 11 |
torch_dtype = torch.float16
|
|
@@ -18,6 +20,8 @@ pipe = pipe.to(device)
|
|
| 18 |
MAX_SEED = np.iinfo(np.int32).max
|
| 19 |
MAX_IMAGE_SIZE = 1024
|
| 20 |
|
|
|
|
|
|
|
| 21 |
def infer(
|
| 22 |
prompt,
|
| 23 |
negative_prompt,
|
|
@@ -27,35 +31,25 @@ def infer(
|
|
| 27 |
height,
|
| 28 |
guidance_scale,
|
| 29 |
num_inference_steps,
|
| 30 |
-
num_images, # নতুন প্যারামিটার: কতগুলো ইমেজ জেনারেট করতে হবে
|
| 31 |
progress=gr.Progress(track_tqdm=True),
|
| 32 |
):
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
width=width,
|
| 51 |
-
height=height,
|
| 52 |
-
generator=generator,
|
| 53 |
-
).images[0]
|
| 54 |
-
|
| 55 |
-
images.append(image)
|
| 56 |
-
seeds_used.append(current_seed)
|
| 57 |
-
|
| 58 |
-
return images, seeds_used
|
| 59 |
|
| 60 |
examples = [
|
| 61 |
"Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
|
|
@@ -68,16 +62,11 @@ css = """
|
|
| 68 |
margin: 0 auto;
|
| 69 |
max-width: 640px;
|
| 70 |
}
|
| 71 |
-
.gallery {
|
| 72 |
-
display: grid;
|
| 73 |
-
grid-template-columns: repeat(2, 1fr);
|
| 74 |
-
gap: 10px;
|
| 75 |
-
}
|
| 76 |
"""
|
| 77 |
|
| 78 |
with gr.Blocks(css=css) as demo:
|
| 79 |
with gr.Column(elem_id="col-container"):
|
| 80 |
-
gr.Markdown(" # Text-to-Image Gradio Template
|
| 81 |
|
| 82 |
with gr.Row():
|
| 83 |
prompt = gr.Text(
|
|
@@ -87,24 +76,12 @@ with gr.Blocks(css=css) as demo:
|
|
| 87 |
placeholder="Enter your prompt",
|
| 88 |
container=False,
|
| 89 |
)
|
|
|
|
| 90 |
run_button = gr.Button("Run", scale=0, variant="primary")
|
| 91 |
|
| 92 |
-
|
| 93 |
-
gallery = gr.Gallery(label="Generated Images", elem_classes="gallery")
|
| 94 |
-
|
| 95 |
-
# ব্যবহৃত সিডগুলো দেখানোর জন্য
|
| 96 |
-
seed_info = gr.Textbox(label="Seeds Used")
|
| 97 |
|
| 98 |
with gr.Accordion("Advanced Settings", open=False):
|
| 99 |
-
# নতুন অপশন: কতগুলো ইমেজ জেনারেট করতে চান
|
| 100 |
-
num_images = gr.Slider(
|
| 101 |
-
label="Number of Images",
|
| 102 |
-
minimum=1,
|
| 103 |
-
maximum=10,
|
| 104 |
-
step=1,
|
| 105 |
-
value=4, # ডিফল্ট ৪টি ইমেজ
|
| 106 |
-
)
|
| 107 |
-
|
| 108 |
negative_prompt = gr.Text(
|
| 109 |
label="Negative prompt",
|
| 110 |
max_lines=1,
|
|
@@ -128,7 +105,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 128 |
minimum=256,
|
| 129 |
maximum=MAX_IMAGE_SIZE,
|
| 130 |
step=32,
|
| 131 |
-
value=1024,
|
| 132 |
)
|
| 133 |
|
| 134 |
height = gr.Slider(
|
|
@@ -136,7 +113,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 136 |
minimum=256,
|
| 137 |
maximum=MAX_IMAGE_SIZE,
|
| 138 |
step=32,
|
| 139 |
-
value=1024,
|
| 140 |
)
|
| 141 |
|
| 142 |
with gr.Row():
|
|
@@ -145,7 +122,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 145 |
minimum=0.0,
|
| 146 |
maximum=10.0,
|
| 147 |
step=0.1,
|
| 148 |
-
value=0.0,
|
| 149 |
)
|
| 150 |
|
| 151 |
num_inference_steps = gr.Slider(
|
|
@@ -153,11 +130,10 @@ with gr.Blocks(css=css) as demo:
|
|
| 153 |
minimum=1,
|
| 154 |
maximum=50,
|
| 155 |
step=1,
|
| 156 |
-
value=2,
|
| 157 |
)
|
| 158 |
|
| 159 |
gr.Examples(examples=examples, inputs=[prompt])
|
| 160 |
-
|
| 161 |
gr.on(
|
| 162 |
triggers=[run_button.click, prompt.submit],
|
| 163 |
fn=infer,
|
|
@@ -170,10 +146,10 @@ with gr.Blocks(css=css) as demo:
|
|
| 170 |
height,
|
| 171 |
guidance_scale,
|
| 172 |
num_inference_steps,
|
| 173 |
-
num_images, # নতুন ইনপুট যোগ করা হয়েছে
|
| 174 |
],
|
| 175 |
-
outputs=[
|
| 176 |
)
|
| 177 |
|
| 178 |
if __name__ == "__main__":
|
| 179 |
-
demo.launch()
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import numpy as np
|
| 3 |
import random
|
| 4 |
+
|
| 5 |
+
# import spaces #[uncomment to use ZeroGPU]
|
| 6 |
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
|
|
|
|
| 20 |
MAX_SEED = np.iinfo(np.int32).max
|
| 21 |
MAX_IMAGE_SIZE = 1024
|
| 22 |
|
| 23 |
+
|
| 24 |
+
# @spaces.GPU #[uncomment to use ZeroGPU]
|
| 25 |
def infer(
|
| 26 |
prompt,
|
| 27 |
negative_prompt,
|
|
|
|
| 31 |
height,
|
| 32 |
guidance_scale,
|
| 33 |
num_inference_steps,
|
|
|
|
| 34 |
progress=gr.Progress(track_tqdm=True),
|
| 35 |
):
|
| 36 |
+
if randomize_seed:
|
| 37 |
+
seed = random.randint(0, MAX_SEED)
|
| 38 |
+
|
| 39 |
+
generator = torch.Generator().manual_seed(seed)
|
| 40 |
+
|
| 41 |
+
image = pipe(
|
| 42 |
+
prompt=prompt,
|
| 43 |
+
negative_prompt=negative_prompt,
|
| 44 |
+
guidance_scale=guidance_scale,
|
| 45 |
+
num_inference_steps=num_inference_steps,
|
| 46 |
+
width=width,
|
| 47 |
+
height=height,
|
| 48 |
+
generator=generator,
|
| 49 |
+
).images[0]
|
| 50 |
+
|
| 51 |
+
return image, seed
|
| 52 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
examples = [
|
| 55 |
"Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
|
|
|
|
| 62 |
margin: 0 auto;
|
| 63 |
max-width: 640px;
|
| 64 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
"""
|
| 66 |
|
| 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(
|
|
|
|
| 76 |
placeholder="Enter your prompt",
|
| 77 |
container=False,
|
| 78 |
)
|
| 79 |
+
|
| 80 |
run_button = gr.Button("Run", scale=0, variant="primary")
|
| 81 |
|
| 82 |
+
result = gr.Image(label="Result", show_label=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
with gr.Accordion("Advanced Settings", open=False):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
negative_prompt = gr.Text(
|
| 86 |
label="Negative prompt",
|
| 87 |
max_lines=1,
|
|
|
|
| 105 |
minimum=256,
|
| 106 |
maximum=MAX_IMAGE_SIZE,
|
| 107 |
step=32,
|
| 108 |
+
value=1024, # Replace with defaults that work for your model
|
| 109 |
)
|
| 110 |
|
| 111 |
height = gr.Slider(
|
|
|
|
| 113 |
minimum=256,
|
| 114 |
maximum=MAX_IMAGE_SIZE,
|
| 115 |
step=32,
|
| 116 |
+
value=1024, # Replace with defaults that work for your model
|
| 117 |
)
|
| 118 |
|
| 119 |
with gr.Row():
|
|
|
|
| 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(
|
|
|
|
| 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],
|
| 139 |
fn=infer,
|
|
|
|
| 146 |
height,
|
| 147 |
guidance_scale,
|
| 148 |
num_inference_steps,
|
|
|
|
| 149 |
],
|
| 150 |
+
outputs=[result, seed],
|
| 151 |
)
|
| 152 |
|
| 153 |
if __name__ == "__main__":
|
| 154 |
+
demo.launch()
|
| 155 |
+
ইসলাম ধর্ম গ্রহণ করেন
|