File size: 1,610 Bytes
517176d
 
0cce2dc
 
36b5ef7
517176d
 
 
 
 
 
 
 
0cce2dc
 
 
 
 
 
 
 
517176d
36b5ef7
0cce2dc
 
 
 
 
 
 
 
517176d
0cce2dc
517176d
 
0cce2dc
 
 
 
 
 
 
 
 
517176d
 
 
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
import gradio as gr
import torch
from diffusers import FluxDiffusionPipeline
from huggingface_hub import hf_hub_download
import spaces

# Load the fine-tuned model
def load_model():
    model_name = "MegaTronX/SuicideGirl-FLUX"  # Replace with your model path
    tokenizer = AutoTokenizer.from_pretrained(model_name)
    model = AutoModelForCausalLM.from_pretrained(model_name)
    return model, tokenizer

# Load the base Flux Dev model
model_id = "black-forest-labs/FLUX.1-dev"
pipeline = FluxDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
pipeline = pipeline.to("cuda")

# Download and load the LoRA weights
lora_model_path = hf_hub_download("MegaTronX/SuicideGirl-FLUX", "SuicideGirls.safetensors")
pipeline.load_lora_weights(lora_model_path)

@spaces.GPU
def generate_image(prompt, negative_prompt, guidance_scale, num_inference_steps):
    image = pipeline(
        prompt=prompt,
        negative_prompt=negative_prompt,
        guidance_scale=guidance_scale,
        num_inference_steps=num_inference_steps
    ).images[0]
    return image

# Create the Gradio interface
iface = gr.Interface(
    fn=generate_image,
    inputs=[
        gr.Textbox(label="Prompt"),
        gr.Textbox(label="Negative Prompt"),
        gr.Slider(minimum=1, maximum=20, value=7.5, label="Guidance Scale"),
        gr.Slider(minimum=1, maximum=100, value=50, step=1, label="Number of Inference Steps")
    ],
    outputs=gr.Image(type="pil"),
    title="Image Generation with Flux Dev LoRA",
    description="Generate images using a Flux Dev model with a custom LoRA fine-tune."
)

iface.launch()