rafaaa2105 commited on
Commit
edf126d
1 Parent(s): 569fafd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -1
app.py CHANGED
@@ -16,6 +16,12 @@ for model_name in model_list:
16
 
17
  @spaces.GPU
18
  def generate_images(model_name, prompt, negative_prompt, num_inference_steps, guidance_scale, num_images=4):
 
 
 
 
 
 
19
  pipe = models[model_name]
20
  outputs = []
21
  for _ in range(num_images):
@@ -23,6 +29,7 @@ def generate_images(model_name, prompt, negative_prompt, num_inference_steps, gu
23
  outputs.append(output)
24
  return outputs
25
 
 
26
  # Create the Gradio blocks
27
  with gr.Blocks() as demo:
28
  with gr.Row(equal_height=False):
@@ -40,6 +47,6 @@ with gr.Blocks() as demo:
40
  with gr.Column():
41
  output_gallery = gr.Gallery(label="Generated Images", height=480, scale=1)
42
 
43
- generate_btn.click(generate_images, inputs=[model_dropdown, prompt, negative_prompt, num_inference_steps, guidance_scale, num_images], outputs=output_gallery)
44
 
45
  demo.launch()
 
16
 
17
  @spaces.GPU
18
  def generate_images(model_name, prompt, negative_prompt, num_inference_steps, guidance_scale, num_images=4):
19
+ if model_name not in models:
20
+ try:
21
+ models[model_name] = DiffusionPipeline.from_pretrained(model_name).to("cuda")
22
+ except Exception as e:
23
+ print(f"Error loading model {model_name}: {e}")
24
+ return []
25
  pipe = models[model_name]
26
  outputs = []
27
  for _ in range(num_images):
 
29
  outputs.append(output)
30
  return outputs
31
 
32
+
33
  # Create the Gradio blocks
34
  with gr.Blocks() as demo:
35
  with gr.Row(equal_height=False):
 
47
  with gr.Column():
48
  output_gallery = gr.Gallery(label="Generated Images", height=480, scale=1)
49
 
50
+ generate_btn.click(generate_images, inputs=[model_dropdown, prompt, negative_prompt, num_inference_steps, guidance_scale, num_images], outputs=output_gallery)
51
 
52
  demo.launch()