aanchal77 commited on
Commit
167f3ce
·
verified ·
1 Parent(s): e87244d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -34
app.py CHANGED
@@ -1,34 +1,37 @@
1
- import gradio as gr
2
- from diffusers import StableDiffusionPipeline
3
- import torch
4
-
5
- # Load base model
6
- pipe = StableDiffusionPipeline.from_pretrained(
7
- "runwayml/stable-diffusion-v1-5",
8
- torch_dtype=torch.float16
9
- )
10
-
11
- # Load LoRA weights from the 'lora' folder
12
- pipe.load_attn_procs("./lora")
13
-
14
- # Move to GPU if available
15
- device = "cuda" if torch.cuda.is_available() else "cpu"
16
- pipe = pipe.to(device)
17
-
18
- # Define image generation function
19
- def generate(prompt):
20
- image = pipe(prompt).images[0]
21
- return image
22
-
23
- # Build Gradio UI
24
- demo = gr.Interface(
25
- fn=generate,
26
- inputs=gr.Textbox(label="Enter your prompt"),
27
- outputs=gr.Image(label="Generated Image"),
28
- title="Fine-tuned Stable Diffusion with LoRA",
29
- description="Enter a prompt and get an AI-generated image based on your fine-tuned model."
30
- )
31
-
32
- # Launch app
33
- if __name__ == "__main__":
34
- demo.launch()
 
 
 
 
1
+ !pip install --upgrade diffusers accelerate transformers safetensors
2
+
3
+
4
+ import gradio as gr
5
+ from diffusers import StableDiffusionPipeline
6
+ import torch
7
+
8
+ # Load base model
9
+ pipe = StableDiffusionPipeline.from_pretrained(
10
+ "runwayml/stable-diffusion-v1-5",
11
+ torch_dtype=torch.float16
12
+ ).to("cuda")
13
+
14
+ # Load LoRA weights from the 'lora' folder
15
+ pipe.load_attn_procs("./lora")
16
+
17
+ # Move to GPU if available
18
+ device = "cuda" if torch.cuda.is_available() else "cpu"
19
+ pipe = pipe.to(device)
20
+
21
+ # Define image generation function
22
+ def generate(prompt):
23
+ image = pipe(prompt).images[0]
24
+ return image
25
+
26
+ # Build Gradio UI
27
+ demo = gr.Interface(
28
+ fn=generate,
29
+ inputs=gr.Textbox(label="Enter your prompt"),
30
+ outputs=gr.Image(label="Generated Image"),
31
+ title="Fine-tuned Stable Diffusion with LoRA",
32
+ description="Enter a prompt and get an AI-generated image based on your fine-tuned model."
33
+ )
34
+
35
+ # Launch app
36
+ if __name__ == "__main__":
37
+ demo.launch()