juxuan27 commited on
Commit
81bbc60
1 Parent(s): 372ced5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -13
app.py CHANGED
@@ -7,6 +7,10 @@ os.system("pip uninstall -y gradio")
7
  os.system("pip install gradio==3.50.0")
8
  print("Installing Finished!")
9
 
 
 
 
 
10
  import cv2
11
  from PIL import Image
12
  import numpy as np
@@ -14,7 +18,6 @@ from segment_anything import SamPredictor, sam_model_registry
14
  import torch
15
  from diffusers import StableDiffusionBrushNetPipeline, BrushNetModel, UniPCMultistepScheduler
16
  import random
17
- import gradio as gr
18
 
19
  mobile_sam = sam_model_registry['vit_h'](checkpoint='data/ckpt/sam_vit_h_4b8939.pth').to("cuda")
20
  mobile_sam.eval()
@@ -33,7 +36,6 @@ image_examples = [
33
  ]
34
 
35
 
36
-
37
  # choose the base model here
38
  base_model_path = "data/ckpt/realisticVisionV60B1_v51VAE"
39
  # base_model_path = "runwayml/stable-diffusion-v1-5"
@@ -41,17 +43,9 @@ base_model_path = "data/ckpt/realisticVisionV60B1_v51VAE"
41
  # input brushnet ckpt path
42
  brushnet_path = "data/ckpt/segmentation_mask_brushnet_ckpt"
43
 
44
- # input source image / mask image path and the text prompt
45
- image_path="examples/brushnet/src/test_image.jpg"
46
- mask_path="examples/brushnet/src/test_mask.jpg"
47
- caption="A cake on the table."
48
-
49
- # conditioning scale
50
- paintingnet_conditioning_scale=1.0
51
-
52
- brushnet = BrushNetModel.from_pretrained(brushnet_path, torch_dtype=torch.float32)
53
  pipe = StableDiffusionBrushNetPipeline.from_pretrained(
54
- base_model_path, brushnet=brushnet, torch_dtype=torch.float32, low_cpu_mem_usage=False
55
  )
56
 
57
  # speed up diffusion process with faster scheduler and memory optimization
@@ -59,7 +53,7 @@ pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
59
  # remove following line if xformers is not installed or when using Torch 2.0.
60
  # pipe.enable_xformers_memory_efficient_attention()
61
  # memory optimization.
62
- # pipe.enable_model_cpu_offload()
63
 
64
  def resize_image(input_image, resolution):
65
  H, W, C = input_image.shape
@@ -73,6 +67,7 @@ def resize_image(input_image, resolution):
73
  img = cv2.resize(input_image, (W, H), interpolation=cv2.INTER_LANCZOS4 if k > 1 else cv2.INTER_AREA)
74
  return img
75
 
 
76
  def process(input_image,
77
  original_image,
78
  original_mask,
 
7
  os.system("pip install gradio==3.50.0")
8
  print("Installing Finished!")
9
 
10
+ ##!/usr/bin/python3
11
+ # -*- coding: utf-8 -*-
12
+ import gradio as gr
13
+ import os
14
  import cv2
15
  from PIL import Image
16
  import numpy as np
 
18
  import torch
19
  from diffusers import StableDiffusionBrushNetPipeline, BrushNetModel, UniPCMultistepScheduler
20
  import random
 
21
 
22
  mobile_sam = sam_model_registry['vit_h'](checkpoint='data/ckpt/sam_vit_h_4b8939.pth').to("cuda")
23
  mobile_sam.eval()
 
36
  ]
37
 
38
 
 
39
  # choose the base model here
40
  base_model_path = "data/ckpt/realisticVisionV60B1_v51VAE"
41
  # base_model_path = "runwayml/stable-diffusion-v1-5"
 
43
  # input brushnet ckpt path
44
  brushnet_path = "data/ckpt/segmentation_mask_brushnet_ckpt"
45
 
46
+ brushnet = BrushNetModel.from_pretrained(brushnet_path, torch_dtype=torch.float16)
 
 
 
 
 
 
 
 
47
  pipe = StableDiffusionBrushNetPipeline.from_pretrained(
48
+ base_model_path, brushnet=brushnet, torch_dtype=torch.float16, low_cpu_mem_usage=False
49
  )
50
 
51
  # speed up diffusion process with faster scheduler and memory optimization
 
53
  # remove following line if xformers is not installed or when using Torch 2.0.
54
  # pipe.enable_xformers_memory_efficient_attention()
55
  # memory optimization.
56
+ pipe.enable_model_cpu_offload()
57
 
58
  def resize_image(input_image, resolution):
59
  H, W, C = input_image.shape
 
67
  img = cv2.resize(input_image, (W, H), interpolation=cv2.INTER_LANCZOS4 if k > 1 else cv2.INTER_AREA)
68
  return img
69
 
70
+
71
  def process(input_image,
72
  original_image,
73
  original_mask,