Spaces:
No application file
No application file
Vo Minh Vu
commited on
Commit
·
e59499b
1
Parent(s):
d270e1b
edit sam model source
Browse files- app.py +9 -4
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -6,12 +6,17 @@ from segment_anything import sam_model_registry, SamAutomaticMaskGenerator
|
|
| 6 |
from tqdm import tqdm
|
| 7 |
from diffusers import StableDiffusionInpaintPipeline, DDIMScheduler
|
| 8 |
from PIL import Image
|
|
|
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
mask_generator = SamAutomaticMaskGenerator(sam)
|
| 13 |
|
| 14 |
-
#
|
| 15 |
scheduler = DDIMScheduler.from_pretrained("runwayml/stable-diffusion-inpainting", subfolder="scheduler")
|
| 16 |
pipe = StableDiffusionInpaintPipeline.from_pretrained(
|
| 17 |
"runwayml/stable-diffusion-inpainting",
|
|
@@ -19,7 +24,7 @@ pipe = StableDiffusionInpaintPipeline.from_pretrained(
|
|
| 19 |
torch_dtype=torch.float32,
|
| 20 |
cache_dir="./models",
|
| 21 |
low_cpu_mem_usage=True
|
| 22 |
-
).to(
|
| 23 |
|
| 24 |
pipe.enable_attention_slicing()
|
| 25 |
|
|
|
|
| 6 |
from tqdm import tqdm
|
| 7 |
from diffusers import StableDiffusionInpaintPipeline, DDIMScheduler
|
| 8 |
from PIL import Image
|
| 9 |
+
from huggingface_hub import hf_hub_download
|
| 10 |
|
| 11 |
+
# 🛠 Kiểm tra thiết bị
|
| 12 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 13 |
+
|
| 14 |
+
# 🏗 Tải mô hình SAM từ Hugging Face
|
| 15 |
+
sam_checkpoint = hf_hub_download(repo_id="facebook/sam", filename="sam_vit_h_4b8939.pth")
|
| 16 |
+
sam = sam_model_registry["vit_h"](checkpoint=sam_checkpoint)
|
| 17 |
mask_generator = SamAutomaticMaskGenerator(sam)
|
| 18 |
|
| 19 |
+
# 🏗 Tải mô hình Stable Diffusion từ Hugging Face
|
| 20 |
scheduler = DDIMScheduler.from_pretrained("runwayml/stable-diffusion-inpainting", subfolder="scheduler")
|
| 21 |
pipe = StableDiffusionInpaintPipeline.from_pretrained(
|
| 22 |
"runwayml/stable-diffusion-inpainting",
|
|
|
|
| 24 |
torch_dtype=torch.float32,
|
| 25 |
cache_dir="./models",
|
| 26 |
low_cpu_mem_usage=True
|
| 27 |
+
).to(device)
|
| 28 |
|
| 29 |
pipe.enable_attention_slicing()
|
| 30 |
|
requirements.txt
CHANGED
|
@@ -9,4 +9,5 @@ pillow
|
|
| 9 |
tqdm
|
| 10 |
diffusers
|
| 11 |
transformers
|
| 12 |
-
segment-anything
|
|
|
|
|
|
| 9 |
tqdm
|
| 10 |
diffusers
|
| 11 |
transformers
|
| 12 |
+
segment-anything
|
| 13 |
+
huggingface_hub
|