File size: 2,441 Bytes
ad0688d
8d7b14b
 
5507320
 
8d7b14b
 
 
 
 
5507320
92b1b58
 
ad0688d
 
 
92b1b58
ad0688d
8d7b14b
92b1b58
 
8d7b14b
 
 
 
 
 
 
 
 
 
 
92b1b58
8d7b14b
 
 
92b1b58
8d7b14b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92b1b58
 
 
 
 
a9bde25
 
 
 
369c4c7
8d7b14b
db7165b
92b1b58
8d7b14b
 
92b1b58
 
8d7b14b
 
 
 
92b1b58
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import os
import torch
from diffusers import DiffusionPipeline
import gradio as gr

# Load the base model and apply the LoRA weights for super realism
def load_pipeline():
    base_model = "black-forest-labs/FLUX.1-dev"
    lora_repo = "strangerzonehf/Flux-Super-Realism-LoRA"
    trigger_word = "Super Realism"  # Recommended trigger word

    

    pipe = DiffusionPipeline.from_pretrained(
        base_model,
        torch_dtype=torch.bfloat16,
       
    )

    # Load the LoRA weights into the pipeline
    pipe.load_lora_weights(lora_repo)

    # Use GPU if available
    device = "cuda" if torch.cuda.is_available() else "cpu"
    pipe.to(device)
    return pipe

# Instantiate the pipeline once on Space startup
pipe = load_pipeline()

# Define a function for image generation
def generate_image(prompt, seed, width, height, guidance_scale, randomize_seed):
    # If randomize_seed is selected, allow the model to generate a random seed
    if randomize_seed:
        seed = None

    # Ensure the prompt includes realism trigger words if needed
    if "realistic" not in prompt.lower() and "realism" not in prompt.lower():
        prompt += " realistic, realism"

    # Generate the image
    output = pipe(
        prompt=prompt,
        seed=seed,
        width=width,
        height=height,
        guidance_scale=guidance_scale
    )
    return output.images[0]

# Set up Gradio interface
iface = gr.Interface(
    fn=generate_image,
    inputs=[
        gr.Textbox(
            lines=2, 
            label="Prompt", 
            placeholder="Enter your prompt, e.g., 'A tiny astronaut hatching from an egg on the moon, 4k, planet theme'"
        ),
        gr.Slider(0, 10000, step=1, value=0, label="Seed (0 for random)"),
        gr.Slider(256, 1024, step=64, value=1024, label="Width"),
        gr.Slider(256, 1024, step=64, value=1024, label="Height"),
        gr.Slider(1, 20, step=0.5, value=6, label="Guidance Scale"),
        gr.Checkbox(value=True, label="Randomize Seed")
    ],
    outputs=gr.Image(type="pil", label="Generated Image"),
    title="Flux Super Realism LoRA Demo",
    description=(
        "This demo uses the Flux Super Realism LoRA model for ultra-realistic image generation. "
        "You can use the trigger word 'Super Realism' (recommended) along with other realism-related words "
        "to guide the generation process."
    ),
)

if __name__ == "__main__":
    iface.launch(share=False)