Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import spaces
|
3 |
+
from diffusers import FluxPipeline
|
4 |
+
import torch
|
5 |
+
|
6 |
+
# Replace with your actual model and LoRA paths
|
7 |
+
BASE_MODEL = "black-forest-labs/FLUX-1-dev"
|
8 |
+
LORA_MODEL = "your_username/your_flux_lora" # Replace with your repo
|
9 |
+
|
10 |
+
# Load base model pipeline
|
11 |
+
pipe = FluxPipeline.from_pretrained(BASE_MODEL, torch_dtype=torch.float16)
|
12 |
+
|
13 |
+
# Load LoRA weights
|
14 |
+
pipe.unet.load_attn_procs(LORA_MODEL)
|
15 |
+
pipe = pipe.to("cuda")
|
16 |
+
|
17 |
+
@spaces.GPU
|
18 |
+
def generate_image(prompt, num_inference_steps=25, guidance_scale=7.5, seed=None):
|
19 |
+
"""Generates an image using the FLUX.1-dev LoRA model."""
|
20 |
+
generator = torch.Generator("cuda").manual_seed(seed) if seed else None
|
21 |
+
|
22 |
+
image = pipe(
|
23 |
+
prompt,
|
24 |
+
num_inference_steps=num_inference_steps,
|
25 |
+
guidance_scale=guidance_scale,
|
26 |
+
generator=generator,
|
27 |
+
).images[0]
|
28 |
+
return image
|
29 |
+
|
30 |
+
# Gradio Interface
|
31 |
+
iface = gr.Interface(
|
32 |
+
fn=generate_image,
|
33 |
+
inputs=[
|
34 |
+
gr.Textbox(lines=3, label="Prompt"),
|
35 |
+
gr.Slider(minimum=10, maximum=100, value=25, label="Inference Steps"),
|
36 |
+
gr.Slider(minimum=1, maximum=15, value=7.5, label="Guidance Scale"),
|
37 |
+
gr.Number(label="Seed (Optional)"),
|
38 |
+
],
|
39 |
+
outputs=gr.Image(label="Generated Image"),
|
40 |
+
title="FLUX.1-dev LoRA Demo",
|
41 |
+
description="A demo of your FLUX.1-dev LoRA model.",
|
42 |
+
)
|
43 |
+
|
44 |
+
iface.launch()
|