tejani commited on
Commit
7586093
·
verified ·
1 Parent(s): 8e51028

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -1,14 +1,20 @@
1
  import gradio as gr
2
- from optimum.intel.openvino import OVStableDiffusionPipeline
3
  import torch
4
 
5
- # Load the quantized model from Hugging Face
6
  model_id = "Intel/sd-1.5-square-quantized"
7
- pipe = OVStableDiffusionPipeline.from_pretrained(model_id, export=False, library_name="diffusers")
 
 
 
 
 
 
 
8
 
9
  # Define the inference function
10
  def generate_image(prompt):
11
- # Generate the image
12
  image = pipe(prompt, num_inference_steps=50, guidance_scale=7.5).images[0]
13
  return image
14
 
 
1
  import gradio as gr
2
+ from diffusers import StableDiffusionPipeline
3
  import torch
4
 
5
+ # Load the model
6
  model_id = "Intel/sd-1.5-square-quantized"
7
+ pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
8
+
9
+ # Optional: Move to CPU (default in Spaces) or enable OpenVINO if available
10
+ try:
11
+ from optimum.intel import OVStableDiffusionPipeline
12
+ pipe = OVStableDiffusionPipeline.from_pretrained(model_id, export=False, library_name="diffusers")
13
+ except (ImportError, ModuleNotFoundError):
14
+ print("Falling back to standard diffusers pipeline (no OpenVINO optimization).")
15
 
16
  # Define the inference function
17
  def generate_image(prompt):
 
18
  image = pipe(prompt, num_inference_steps=50, guidance_scale=7.5).images[0]
19
  return image
20