DonImages commited on
Commit
9b047cb
·
verified ·
1 Parent(s): d30f159

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -6
app.py CHANGED
@@ -11,9 +11,9 @@ if token:
11
  else:
12
  raise ValueError("Hugging Face token not found. Please set it as a repository secret in the Space settings.")
13
 
14
- # Load the Stable Diffusion 3.5 model
15
  model_id = "stabilityai/stable-diffusion-3.5-large"
16
- pipe = StableDiffusion3Pipeline.from_pretrained(model_id) # Removed torch_dtype argument
17
  pipe.to("cpu") # Ensuring it runs on CPU
18
 
19
  # Define the path to the LoRA model
@@ -37,10 +37,10 @@ pipe = load_lora_model(pipe, lora_model_path)
37
  # Function to generate an image from a text prompt
38
  def generate_image(prompt, seed=None):
39
  generator = torch.manual_seed(seed) if seed is not None else None
40
- image = pipe(prompt, height=1080, width=1080, generator=generator).images[0]
 
41
  return image
42
 
43
-
44
  # Gradio interface
45
  iface = gr.Interface(
46
  fn=generate_image,
@@ -50,5 +50,4 @@ iface = gr.Interface(
50
  ],
51
  outputs="image"
52
  )
53
- iface.launch()
54
-
 
11
  else:
12
  raise ValueError("Hugging Face token not found. Please set it as a repository secret in the Space settings.")
13
 
14
+ # Load the Stable Diffusion 3.5 model with lower precision (float16)
15
  model_id = "stabilityai/stable-diffusion-3.5-large"
16
+ pipe = StableDiffusion3Pipeline.from_pretrained(model_id, torch_dtype=torch.float16) # Use float16 precision
17
  pipe.to("cpu") # Ensuring it runs on CPU
18
 
19
  # Define the path to the LoRA model
 
37
  # Function to generate an image from a text prompt
38
  def generate_image(prompt, seed=None):
39
  generator = torch.manual_seed(seed) if seed is not None else None
40
+ # Reduce image size for less memory usage
41
+ image = pipe(prompt, height=512, width=512, generator=generator).images[0] # Changed image size
42
  return image
43
 
 
44
  # Gradio interface
45
  iface = gr.Interface(
46
  fn=generate_image,
 
50
  ],
51
  outputs="image"
52
  )
53
+ iface.launch()