MegaTronX commited on
Commit
4b9df77
Β·
verified Β·
1 Parent(s): ce3f469

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ import spaces
4
+ from diffusers import FluxPipeline
5
+ from safetensors.torch import load_file
6
+
7
+ # Load the Flux Dev model
8
+ model_id = "black-forest-labs/FLUX.1-dev"
9
+ pipe = FluxPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
10
+ pipe.to("cuda")
11
+
12
+ # Load the LoRA weights
13
+ lora_path = "MegaTronX/SuicideGirl-FLUX"
14
+ lora_weights = load_file(lora_path)
15
+
16
+ # Apply LoRA weights to the model
17
+ pipe.unet.load_attn_procs(lora_weights)
18
+
19
+ @spaces.GPU
20
+ def generate_image(prompt, negative_prompt, guidance_scale, num_inference_steps, lora_scale):
21
+ with torch.inference_mode():
22
+ image = pipe(
23
+ prompt=prompt,
24
+ negative_prompt=negative_prompt,
25
+ num_inference_steps=num_inference_steps,
26
+ guidance_scale=guidance_scale,
27
+ cross_attention_kwargs={"scale": lora_scale},
28
+ ).images[0]
29
+ return image
30
+
31
+ # Create the Gradio interface
32
+ iface = gr.Interface(
33
+ fn=generate_image,
34
+ inputs=[
35
+ gr.Textbox(label="Prompt"),
36
+ gr.Textbox(label="Negative Prompt"),
37
+ gr.Slider(1, 20, value=7.5, label="Guidance Scale"),
38
+ gr.Slider(1, 100, value=50, step=1, label="Number of Inference Steps"),
39
+ gr.Slider(0, 1, value=0.75, label="LoRA Scale"),
40
+ ],
41
+ outputs=gr.Image(type="pil"),
42
+ title="Flux Dev with Custom LoRA Image Generator",
43
+ description="Generate images using Flux Dev model with a custom LoRA trained on Civitai",
44
+ )
45
+
46
+ iface.launch()