MegaTronX commited on
Commit
2b9dd70
Β·
verified Β·
1 Parent(s): 6321546

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from diffusers import StableDiffusionPipeline
3
+ import torch
4
+ import spaces
5
+
6
+ @spaces.GPU
7
+ def generate_image(prompt, num_inference_steps, guidance_scale):
8
+ # Load the base model
9
+ base_model_id = "black-forest-labs/FLUX.1-dev"
10
+ pipe = StableDiffusionPipeline.from_pretrained(base_model_id, torch_dtype=torch.float16)
11
+
12
+ # Load the LoRA weights
13
+ pipe.unet.load_attn_procs("MegaTronX/SuicideGirl-FLUX")
14
+
15
+ pipe = pipe.to("cuda")
16
+
17
+ # Generate the image
18
+ image = pipe(
19
+ prompt,
20
+ num_inference_steps=num_inference_steps,
21
+ guidance_scale=guidance_scale
22
+ ).images[0]
23
+
24
+ return image
25
+
26
+ # Create the Gradio interface
27
+ iface = gr.Interface(
28
+ fn=generate_image,
29
+ inputs=[
30
+ gr.Textbox(label="Prompt"),
31
+ gr.Slider(minimum=1, maximum=100, value=50, label="Number of Inference Steps"),
32
+ gr.Slider(minimum=1, maximum=20, value=7.5, label="Guidance Scale")
33
+ ],
34
+ outputs=gr.Image(label="Generated Image"),
35
+ title="Image Generation with Custom LoRA",
36
+ description="Generate images using a custom LoRA model trained on Flux Dev."
37
+ )
38
+
39
+ iface.launch()