RanM commited on
Commit
61d26c4
·
verified ·
1 Parent(s): 5422562

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -5,16 +5,18 @@ from diffusers import AutoPipelineForText2Image
5
  import gradio as gr
6
  import base64
7
 
8
- # Load the model once at the start
9
- print("Loading the Stable Diffusion model...")
10
- try:
11
- model = AutoPipelineForText2Image.from_pretrained("stabilityai/sdxl-turbo")
12
- print("Model loaded successfully.")
13
- except Exception as e:
14
- print(f"Error loading model: {e}")
15
- model = None
 
16
 
17
  def generate_image(prompt):
 
18
  try:
19
  if model is None:
20
  raise ValueError("Model not loaded properly.")
 
5
  import gradio as gr
6
  import base64
7
 
8
+ def load_model():
9
+ print("Loading the Stable Diffusion model...")
10
+ try:
11
+ model = AutoPipelineForText2Image.from_pretrained("stabilityai/sdxl-turbo")
12
+ print("Model loaded successfully.")
13
+ return model
14
+ except Exception as e:
15
+ print(f"Error loading model: {e}")
16
+ return None
17
 
18
  def generate_image(prompt):
19
+ model = load_model()
20
  try:
21
  if model is None:
22
  raise ValueError("Model not loaded properly.")