Walid-Ahmed commited on
Commit
532bae2
·
verified ·
1 Parent(s): ad8fc38

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -9
app.py CHANGED
@@ -2,7 +2,7 @@ import torch
2
  import gradio as gr
3
  import spaces # Import spaces for ZeroGPU support
4
  from functools import lru_cache
5
- from diffusers import DiffusionPipeline
6
 
7
  # LoRA model path on Hugging Face Hub
8
  color_book_lora_path = "artificialguybr/ColoringBookRedmond-V2"
@@ -11,14 +11,13 @@ color_book_trigger = ", ColoringBookAF, Coloring Book"
11
  # Load model on CPU initially
12
  @lru_cache(maxsize=1)
13
  def load_pipeline(use_lora: bool):
14
- """Load Stable Diffusion pipeline and LoRA weights (if selected)."""
15
 
16
- # Load the base model
17
- pipe = DiffusionPipeline.from_pretrained(
18
- "stabilityai/stable-diffusion-xl-refiner-1.0",
19
  torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
20
- use_safetensors=True,
21
- variant="fp16" if torch.cuda.is_available() else None
22
  )
23
 
24
  # Keep the model on CPU until GPU is requested
@@ -57,7 +56,7 @@ styles = {
57
 
58
  @spaces.GPU # ZeroGPU: Allocate GPU only when generating images
59
  def generate_image(prompt: str, style_name: str, use_lora: bool):
60
- """Generate an image using Stable Diffusion with optional LoRA fine-tuning."""
61
 
62
  # Load the pipeline (cached)
63
  pipeline = load_pipeline(use_lora)
@@ -73,7 +72,7 @@ def generate_image(prompt: str, style_name: str, use_lora: bool):
73
  if use_lora:
74
  prompt += color_book_trigger
75
 
76
- # Generate image
77
  image = pipeline(
78
  prompt=prompt + " " + style_prompt,
79
  negative_prompt="blurred, ugly, watermark, low resolution, " + negative_prompt,
 
2
  import gradio as gr
3
  import spaces # Import spaces for ZeroGPU support
4
  from functools import lru_cache
5
+ from diffusers import StableDiffusionXLPipeline # ✅ Correct pipeline for text-to-image
6
 
7
  # LoRA model path on Hugging Face Hub
8
  color_book_lora_path = "artificialguybr/ColoringBookRedmond-V2"
 
11
  # Load model on CPU initially
12
  @lru_cache(maxsize=1)
13
  def load_pipeline(use_lora: bool):
14
+ """Load Stable Diffusion XL pipeline and LoRA weights (if selected)."""
15
 
16
+ # Use StableDiffusionXLPipeline for text-to-image generation
17
+ pipe = StableDiffusionXLPipeline.from_pretrained(
18
+ "stabilityai/stable-diffusion-xl-base-1.0",
19
  torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
20
+ use_safetensors=True
 
21
  )
22
 
23
  # Keep the model on CPU until GPU is requested
 
56
 
57
  @spaces.GPU # ZeroGPU: Allocate GPU only when generating images
58
  def generate_image(prompt: str, style_name: str, use_lora: bool):
59
+ """Generate an image using Stable Diffusion XL with optional LoRA fine-tuning."""
60
 
61
  # Load the pipeline (cached)
62
  pipeline = load_pipeline(use_lora)
 
72
  if use_lora:
73
  prompt += color_book_trigger
74
 
75
+ # Ensure text-to-image pipeline is used correctly
76
  image = pipeline(
77
  prompt=prompt + " " + style_prompt,
78
  negative_prompt="blurred, ugly, watermark, low resolution, " + negative_prompt,