jiuface commited on
Commit
d74c6d6
1 Parent(s): d0852ef
Files changed (2) hide show
  1. README.md +1 -1
  2. app.py +18 -20
README.md CHANGED
@@ -4,7 +4,7 @@ emoji: 🖼
4
  colorFrom: purple
5
  colorTo: red
6
  sdk: gradio
7
- sdk_version: 4.29
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
 
4
  colorFrom: purple
5
  colorTo: red
6
  sdk: gradio
7
+ sdk_version: 4.29.0
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
app.py CHANGED
@@ -17,28 +17,29 @@ from diffusers import (
17
  from transformers import DPTFeatureExtractor, DPTForDepthEstimation, DPTImageProcessor
18
  from transformers import CLIPImageProcessor
19
  from diffusers.utils import load_image
20
-
 
21
  device = "cuda"
22
  base_model_id = "SG161222/RealVisXL_V4.0"
23
  controlnet_model_id = "diffusers/controlnet-depth-sdxl-1.0"
24
  vae_model_id = "madebyollin/sdxl-vae-fp16-fix"
25
 
26
 
27
- # load pipe
28
- controlnet = ControlNetModel.from_pretrained(controlnet_model_id, variant="fp16", use_safetensors=True, torch_dtype=torch.float16)
29
- vae = AutoencoderKL.from_pretrained(vae_model_id, torch_dtype=torch.float16)
30
- pipe = StableDiffusionXLControlNetPipeline.from_pretrained(
31
- base_model_id,
32
- controlnet=controlnet,
33
- vae=vae,
34
- variant="fp16",
35
- use_safetensors=True,
36
- torch_dtype=torch.float16,
37
- )
38
- pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config)
39
- pipe.enable_model_cpu_offload()
40
- pipe.enable_xformers_memory_efficient_attention()
41
- pipe.to(device)
42
 
43
  depth_estimator = DPTForDepthEstimation.from_pretrained("Intel/dpt-hybrid-midas").to("cuda")
44
  feature_extractor = DPTImageProcessor.from_pretrained("Intel/dpt-hybrid-midas")
@@ -79,7 +80,7 @@ def get_depth_map(image):
79
 
80
 
81
  @spaces.GPU(enable_queue=True)
82
- def process(orginal_image, image_url, prompt, a_prompt, n_prompt, num_steps, guidance_scale, control_strength, seed):
83
 
84
  if image_url:
85
  orginal_image = load_image(image_url)
@@ -117,7 +118,6 @@ with gr.Blocks() as demo:
117
  control_strength = gr.Slider(label="Control Strength", minimum=0.1, maximum=4.0, value=0.8, step=0.1)
118
  seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=0)
119
  randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
120
- a_prompt = gr.Textbox(label="Additional prompt", value="high-quality, extremely detailed, 4K")
121
  n_prompt = gr.Textbox(
122
  label="Negative prompt",
123
  value="longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality",
@@ -130,7 +130,6 @@ with gr.Blocks() as demo:
130
  image,
131
  image_url,
132
  prompt,
133
- a_prompt,
134
  n_prompt,
135
  num_steps,
136
  guidance_scale,
@@ -149,6 +148,5 @@ with gr.Blocks() as demo:
149
  outputs=[result, logs],
150
  api_name=False
151
  )
152
- return demo
153
 
154
  demo.queue().launch()
 
17
  from transformers import DPTFeatureExtractor, DPTForDepthEstimation, DPTImageProcessor
18
  from transformers import CLIPImageProcessor
19
  from diffusers.utils import load_image
20
+ from gradio_imageslider import ImageSlider
21
+
22
  device = "cuda"
23
  base_model_id = "SG161222/RealVisXL_V4.0"
24
  controlnet_model_id = "diffusers/controlnet-depth-sdxl-1.0"
25
  vae_model_id = "madebyollin/sdxl-vae-fp16-fix"
26
 
27
 
28
+ if torch.cuda.is_available():
29
+
30
+ # load pipe
31
+ controlnet = ControlNetModel.from_pretrained(controlnet_model_id, variant="fp16", use_safetensors=True, torch_dtype=torch.float16)
32
+ vae = AutoencoderKL.from_pretrained(vae_model_id, torch_dtype=torch.float16)
33
+ pipe = StableDiffusionXLControlNetPipeline.from_pretrained(
34
+ base_model_id,
35
+ controlnet=controlnet,
36
+ vae=vae,
37
+ variant="fp16",
38
+ use_safetensors=True,
39
+ torch_dtype=torch.float16,
40
+ )
41
+ pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config)
42
+ pipe.to(device)
43
 
44
  depth_estimator = DPTForDepthEstimation.from_pretrained("Intel/dpt-hybrid-midas").to("cuda")
45
  feature_extractor = DPTImageProcessor.from_pretrained("Intel/dpt-hybrid-midas")
 
80
 
81
 
82
  @spaces.GPU(enable_queue=True)
83
+ def process(orginal_image, image_url, prompt, n_prompt, num_steps, guidance_scale, control_strength, seed):
84
 
85
  if image_url:
86
  orginal_image = load_image(image_url)
 
118
  control_strength = gr.Slider(label="Control Strength", minimum=0.1, maximum=4.0, value=0.8, step=0.1)
119
  seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=0)
120
  randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
 
121
  n_prompt = gr.Textbox(
122
  label="Negative prompt",
123
  value="longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality",
 
130
  image,
131
  image_url,
132
  prompt,
 
133
  n_prompt,
134
  num_steps,
135
  guidance_scale,
 
148
  outputs=[result, logs],
149
  api_name=False
150
  )
 
151
 
152
  demo.queue().launch()