Fix'er Upper
Browse files- Updated Gradio preflight installation to allow patch updates within 3.50.x
- Switched model setup to use CPU instead of GPU for compatibility with Hugging Face free tier
- Removed references to half-precision (torch.float16) in favor of full precision (torch.float32) to accommodate CPU environments
app.py
CHANGED
|
@@ -1,16 +1,12 @@
|
|
| 1 |
-
##!/usr/bin/python3
|
| 2 |
# -*- coding: utf-8 -*-
|
| 3 |
import os
|
| 4 |
|
| 5 |
print("Installing correct gradio version...")
|
| 6 |
-
os.system("pip
|
| 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
|
|
@@ -19,7 +15,7 @@ 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("
|
| 23 |
mobile_sam.eval()
|
| 24 |
mobile_predictor = SamPredictor(mobile_sam)
|
| 25 |
colors = [(255, 0, 0), (0, 255, 0)]
|
|
@@ -42,9 +38,9 @@ base_model_path = "data/ckpt/realisticVisionV60B1_v51VAE"
|
|
| 42 |
# input brushnet ckpt path
|
| 43 |
brushnet_path = "data/ckpt/segmentation_mask_brushnet_ckpt"
|
| 44 |
|
| 45 |
-
brushnet = BrushNetModel.from_pretrained(brushnet_path, torch_dtype=torch.
|
| 46 |
pipe = StableDiffusionBrushNetPipeline.from_pretrained(
|
| 47 |
-
base_model_path, brushnet=brushnet, torch_dtype=torch.
|
| 48 |
)
|
| 49 |
|
| 50 |
# speed up diffusion process with faster scheduler and memory optimization
|
|
@@ -107,7 +103,7 @@ def process(input_image,
|
|
| 107 |
init_image = Image.fromarray(masked_image.astype(np.uint8)).convert("RGB")
|
| 108 |
mask_image = Image.fromarray(original_mask.astype(np.uint8)).convert("RGB")
|
| 109 |
|
| 110 |
-
generator = torch.Generator("
|
| 111 |
|
| 112 |
image = pipe(
|
| 113 |
[prompt]*2,
|
|
|
|
| 1 |
+
##!/usr/bin/env python3
|
| 2 |
# -*- coding: utf-8 -*-
|
| 3 |
import os
|
| 4 |
|
| 5 |
print("Installing correct gradio version...")
|
| 6 |
+
os.system("pip install 'gradio>=3.50.0,<3.51.0' --force-reinstall -q")
|
|
|
|
| 7 |
print("Installing Finished!")
|
| 8 |
|
|
|
|
|
|
|
| 9 |
import gradio as gr
|
|
|
|
| 10 |
import cv2
|
| 11 |
from PIL import Image
|
| 12 |
import numpy as np
|
|
|
|
| 15 |
from diffusers import StableDiffusionBrushNetPipeline, BrushNetModel, UniPCMultistepScheduler
|
| 16 |
import random
|
| 17 |
|
| 18 |
+
mobile_sam = sam_model_registry['vit_h'](checkpoint='data/ckpt/sam_vit_h_4b8939.pth').to("cpu")
|
| 19 |
mobile_sam.eval()
|
| 20 |
mobile_predictor = SamPredictor(mobile_sam)
|
| 21 |
colors = [(255, 0, 0), (0, 255, 0)]
|
|
|
|
| 38 |
# input brushnet ckpt path
|
| 39 |
brushnet_path = "data/ckpt/segmentation_mask_brushnet_ckpt"
|
| 40 |
|
| 41 |
+
brushnet = BrushNetModel.from_pretrained(brushnet_path, torch_dtype=torch.float32)
|
| 42 |
pipe = StableDiffusionBrushNetPipeline.from_pretrained(
|
| 43 |
+
base_model_path, brushnet=brushnet, torch_dtype=torch.float32, low_cpu_mem_usage=False
|
| 44 |
)
|
| 45 |
|
| 46 |
# speed up diffusion process with faster scheduler and memory optimization
|
|
|
|
| 103 |
init_image = Image.fromarray(masked_image.astype(np.uint8)).convert("RGB")
|
| 104 |
mask_image = Image.fromarray(original_mask.astype(np.uint8)).convert("RGB")
|
| 105 |
|
| 106 |
+
generator = torch.Generator("cpu").manual_seed(random.randint(0,2147483647) if randomize_seed else seed)
|
| 107 |
|
| 108 |
image = pipe(
|
| 109 |
[prompt]*2,
|