RanM commited on
Commit
ea8a0d1
·
verified ·
1 Parent(s): 75bb6a7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -11
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.")
@@ -74,9 +76,9 @@ gradio_interface = gr.Interface(
74
  gr.JSON(label="Character Dict"),
75
  gr.Dropdown(["oil painting", "sketch", "watercolor"], label="Selected Style")
76
  ],
77
- outputs="json"
78
- )
79
 
80
  if __name__ == "__main__":
81
  print("Launching Gradio interface...")
82
- gradio_interface.launch()
 
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.")
 
76
  gr.JSON(label="Character Dict"),
77
  gr.Dropdown(["oil painting", "sketch", "watercolor"], label="Selected Style")
78
  ],
79
+ outputs="json",
80
+ concurrency_limit=3)
81
 
82
  if __name__ == "__main__":
83
  print("Launching Gradio interface...")
84
+ gradio_interface.launch()