Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,20 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
import torch
|
4 |
|
5 |
-
# Load the
|
6 |
model_id = "Intel/sd-1.5-square-quantized"
|
7 |
-
pipe =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|