Spaces:
vilarin
/
Running on Zero

vilarin commited on
Commit
e7915f0
1 Parent(s): 6380dba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -1,6 +1,6 @@
1
  import gradio as gr
2
  import torch
3
- from diffusers import StableDiffusionXLPipeline, EulerDiscreteScheduler
4
  from huggingface_hub import hf_hub_download
5
  import spaces
6
  from PIL import Image
@@ -22,7 +22,8 @@ CSS = """
22
 
23
  # Ensure model and scheduler are initialized in GPU-enabled function
24
  if torch.cuda.is_available():
25
- pipe = StableDiffusionXLPipeline.from_pretrained(base, torch_dtype=torch.float16, variant="fp16").to("cuda")
 
26
 
27
 
28
  # Function
@@ -35,7 +36,7 @@ def generate_image(prompt, ckpt):
35
  num_inference_steps = checkpoints[ckpt][1]
36
 
37
  if loaded != num_inference_steps:
38
- pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing", prediction_type="sample" if num_inference_steps==1 else "epsilon")
39
  pipe.unet.load_state_dict(torch.load(hf_hub_download(repo, checkpoint), map_location="cuda"))
40
  loaded = num_inference_steps
41
 
@@ -54,7 +55,7 @@ with gr.Blocks(css=CSS) as demo:
54
  with gr.Group():
55
  with gr.Row():
56
  prompt = gr.Textbox(label='Enter your prompt (English)', scale=8)
57
- ckpt = gr.Dropdown(label='Select inference steps',choices=['1-Step', '2-Step', '4-Step', '8-Step'], value='4-Step', interactive=True)
58
  submit = gr.Button(scale=1, variant='primary')
59
  img = gr.Image(label='DMD2 Generated Image')
60
 
 
1
  import gradio as gr
2
  import torch
3
+ from diffusers import DiffusionPipeline, UNet2DConditionModel, LCMScheduler
4
  from huggingface_hub import hf_hub_download
5
  import spaces
6
  from PIL import Image
 
22
 
23
  # Ensure model and scheduler are initialized in GPU-enabled function
24
  if torch.cuda.is_available():
25
+ unet = UNet2DConditionModel.from_config(base, subfolder="unet").to("cuda", torch.float16)
26
+ pipe = DiffusionPipeline.from_pretrained(base, torch_dtype=torch.float16, variant="fp16").to("cuda")
27
 
28
 
29
  # Function
 
36
  num_inference_steps = checkpoints[ckpt][1]
37
 
38
  if loaded != num_inference_steps:
39
+ pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing", prediction_type="sample" if num_inference_steps==1 else "epsilon")
40
  pipe.unet.load_state_dict(torch.load(hf_hub_download(repo, checkpoint), map_location="cuda"))
41
  loaded = num_inference_steps
42
 
 
55
  with gr.Group():
56
  with gr.Row():
57
  prompt = gr.Textbox(label='Enter your prompt (English)', scale=8)
58
+ ckpt = gr.Dropdown(label='Select inference steps',choices=['1-Step', '4-Step'], value='4-Step', interactive=True)
59
  submit = gr.Button(scale=1, variant='primary')
60
  img = gr.Image(label='DMD2 Generated Image')
61