Clone04 commited on
Commit
64a5f0f
·
verified ·
1 Parent(s): fbb39d3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -1,15 +1,17 @@
1
  import gradio as gr
2
  from optimum.intel import OVDiffusionPipeline
3
  import torch
 
4
 
5
- # Load the FLUX.1-schnell model optimized with OpenVINO (INT4)
6
  model_id = "OpenVINO/FLUX.1-schnell-int4-ov"
7
  pipeline = OVDiffusionPipeline.from_pretrained(model_id, device="CPU")
 
8
 
9
  # Define the image generation function
10
  def generate_image(prompt):
11
- # Generate the image using the pipeline
12
- image = pipeline(prompt, num_inference_steps=4, guidance_scale=3.5).images[0]
13
  return image
14
 
15
  # Create the Gradio interface
@@ -20,8 +22,9 @@ interface = gr.Interface(
20
  title="FLUX.1-Schnell (OpenVINO INT4) Image Generator",
21
  description="Generate images from text prompts using FLUX.1-schnell optimized for CPU with OpenVINO.",
22
  examples=[["A serene mountain landscape"], ["A cyberpunk city at night"]],
 
23
  )
24
 
25
- # Launch the interface
26
  if __name__ == "__main__":
27
- interface.launch()
 
1
  import gradio as gr
2
  from optimum.intel import OVDiffusionPipeline
3
  import torch
4
+ from threading import Lock
5
 
6
+ # Load the pipeline globally
7
  model_id = "OpenVINO/FLUX.1-schnell-int4-ov"
8
  pipeline = OVDiffusionPipeline.from_pretrained(model_id, device="CPU")
9
+ lock = Lock()
10
 
11
  # Define the image generation function
12
  def generate_image(prompt):
13
+ with lock:
14
+ image = pipeline(prompt, num_inference_steps=4, guidance_scale=3.5).images[0]
15
  return image
16
 
17
  # Create the Gradio interface
 
22
  title="FLUX.1-Schnell (OpenVINO INT4) Image Generator",
23
  description="Generate images from text prompts using FLUX.1-schnell optimized for CPU with OpenVINO.",
24
  examples=[["A serene mountain landscape"], ["A cyberpunk city at night"]],
25
+ cache_examples=False
26
  )
27
 
28
+ # Launch the interface with queueing
29
  if __name__ == "__main__":
30
+ interface.launch(queue=True)