Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,11 +20,9 @@ torch.backends.cuda.matmul.allow_tf32 = True
|
|
| 20 |
class timer:
|
| 21 |
def __init__(self, method_name="timed process"):
|
| 22 |
self.method = method_name
|
| 23 |
-
|
| 24 |
def __enter__(self):
|
| 25 |
self.start = time.time()
|
| 26 |
print(f"{self.method} starts")
|
| 27 |
-
|
| 28 |
def __exit__(self, exc_type, exc_val, exc_tb):
|
| 29 |
end = time.time()
|
| 30 |
print(f"{self.method} took {str(round(end - self.start, 2))}s")
|
|
@@ -37,41 +35,71 @@ pipe.load_lora_weights(hf_hub_download("ByteDance/Hyper-SD", "Hyper-FLUX.1-dev-8
|
|
| 37 |
pipe.fuse_lora(lora_scale=0.125)
|
| 38 |
pipe.to(device="cuda", dtype=torch.bfloat16)
|
| 39 |
|
| 40 |
-
with gr.Blocks() as demo:
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
with
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
with
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
if __name__ == "__main__":
|
| 77 |
-
demo.launch()
|
|
|
|
| 20 |
class timer:
|
| 21 |
def __init__(self, method_name="timed process"):
|
| 22 |
self.method = method_name
|
|
|
|
| 23 |
def __enter__(self):
|
| 24 |
self.start = time.time()
|
| 25 |
print(f"{self.method} starts")
|
|
|
|
| 26 |
def __exit__(self, exc_type, exc_val, exc_tb):
|
| 27 |
end = time.time()
|
| 28 |
print(f"{self.method} took {str(round(end - self.start, 2))}s")
|
|
|
|
| 35 |
pipe.fuse_lora(lora_scale=0.125)
|
| 36 |
pipe.to(device="cuda", dtype=torch.bfloat16)
|
| 37 |
|
| 38 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 39 |
+
gr.Markdown(
|
| 40 |
+
"""
|
| 41 |
+
<div style="text-align: center; max-width: 650px; margin: 0 auto;">
|
| 42 |
+
<h1 style="font-size: 2.5rem; font-weight: 700; margin-bottom: 1rem;">FLUX Image Generator</h1>
|
| 43 |
+
<p style="font-size: 1rem; margin-bottom: 1.5rem;">Create unique images with AI. Just describe what you want to see!</p>
|
| 44 |
+
</div>
|
| 45 |
+
"""
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
with gr.Group():
|
| 49 |
+
prompt = gr.Textbox(
|
| 50 |
+
label="Your Image Description",
|
| 51 |
+
placeholder="E.g., A serene landscape with mountains and a lake at sunset",
|
| 52 |
+
lines=3
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
with gr.Accordion("Advanced Settings", open=False):
|
| 56 |
+
with gr.Group():
|
| 57 |
+
with gr.Row():
|
| 58 |
+
height = gr.Slider(label="Height", minimum=256, maximum=1024, step=64, value=1024)
|
| 59 |
+
width = gr.Slider(label="Width", minimum=256, maximum=1024, step=64, value=1024)
|
| 60 |
+
|
| 61 |
+
with gr.Row():
|
| 62 |
+
steps = gr.Slider(label="Inference Steps", minimum=6, maximum=25, step=1, value=8)
|
| 63 |
+
scales = gr.Slider(label="Guidance Scale", minimum=0.0, maximum=5.0, step=0.1, value=3.5)
|
| 64 |
+
|
| 65 |
+
seed = gr.Number(label="Seed (for reproducibility)", value=3413, precision=0)
|
| 66 |
+
|
| 67 |
+
generate_btn = gr.Button("Generate Image", variant="primary", scale=1)
|
| 68 |
+
|
| 69 |
+
output = gr.Image(label="Your Generated Image")
|
| 70 |
+
|
| 71 |
+
gr.Markdown(
|
| 72 |
+
"""
|
| 73 |
+
<div style="max-width: 650px; margin: 2rem auto; padding: 1rem; border-radius: 10px; background-color: #f0f0f0;">
|
| 74 |
+
<h2 style="font-size: 1.5rem; margin-bottom: 1rem;">How to Use</h2>
|
| 75 |
+
<ol style="padding-left: 1.5rem;">
|
| 76 |
+
<li>Enter a detailed description of the image you want to create.</li>
|
| 77 |
+
<li>Adjust advanced settings if desired (tap to expand).</li>
|
| 78 |
+
<li>Tap "Generate Image" and wait for your creation!</li>
|
| 79 |
+
</ol>
|
| 80 |
+
<p style="margin-top: 1rem; font-style: italic;">Tip: Be specific in your description for best results!</p>
|
| 81 |
+
</div>
|
| 82 |
+
"""
|
| 83 |
+
)
|
| 84 |
|
| 85 |
+
@spaces.GPU
|
| 86 |
+
def process_image(height, width, steps, scales, prompt, seed):
|
| 87 |
+
global pipe
|
| 88 |
+
with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16), timer("inference"):
|
| 89 |
+
return pipe(
|
| 90 |
+
prompt=[prompt],
|
| 91 |
+
generator=torch.Generator().manual_seed(int(seed)),
|
| 92 |
+
num_inference_steps=int(steps),
|
| 93 |
+
guidance_scale=float(scales),
|
| 94 |
+
height=int(height),
|
| 95 |
+
width=int(width)
|
| 96 |
+
).images
|
| 97 |
|
| 98 |
+
generate_btn.click(
|
| 99 |
+
process_image,
|
| 100 |
+
inputs=[height, width, steps, scales, prompt, seed],
|
| 101 |
+
outputs=[output]
|
| 102 |
+
)
|
| 103 |
|
| 104 |
if __name__ == "__main__":
|
| 105 |
+
demo.launch()
|