Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,7 +10,7 @@ from typing import Tuple, Optional
|
|
| 10 |
|
| 11 |
from PIL import Image
|
| 12 |
from gradio_imageslider import ImageSlider
|
| 13 |
-
from transformers import AutoModelForImageSegmentation
|
| 14 |
from torchvision import transforms
|
| 15 |
|
| 16 |
import requests
|
|
@@ -18,6 +18,9 @@ from io import BytesIO
|
|
| 18 |
import zipfile
|
| 19 |
import random
|
| 20 |
|
|
|
|
|
|
|
|
|
|
| 21 |
torch.set_float32_matmul_precision('high')
|
| 22 |
torch.jit.script = lambda f: f
|
| 23 |
|
|
@@ -75,12 +78,9 @@ usage_to_weights_file = {
|
|
| 75 |
'General-legacy': 'BiRefNet-legacy'
|
| 76 |
}
|
| 77 |
|
| 78 |
-
# 모델 로딩 전에 tie_weights()를 빈 함수로 재정의(우회)
|
| 79 |
-
AutoModelForImageSegmentation.tie_weights = lambda self: None
|
| 80 |
-
|
| 81 |
# 초기 모델 로딩 (기본: General)
|
| 82 |
birefnet = AutoModelForImageSegmentation.from_pretrained(
|
| 83 |
-
'/'.join(('zhengpeng7', usage_to_weights_file['General'])),
|
| 84 |
trust_remote_code=True
|
| 85 |
)
|
| 86 |
birefnet.to(device)
|
|
|
|
| 10 |
|
| 11 |
from PIL import Image
|
| 12 |
from gradio_imageslider import ImageSlider
|
| 13 |
+
from transformers import AutoModelForImageSegmentation, PretrainedConfig
|
| 14 |
from torchvision import transforms
|
| 15 |
|
| 16 |
import requests
|
|
|
|
| 18 |
import zipfile
|
| 19 |
import random
|
| 20 |
|
| 21 |
+
# monkey-patch: get_text_config를 덮어써서 dummy 객체를 반환 (tie_word_embeddings=False)
|
| 22 |
+
PretrainedConfig.get_text_config = lambda self, decoder=True: type("DummyTextConfig", (), {"tie_word_embeddings": False})()
|
| 23 |
+
|
| 24 |
torch.set_float32_matmul_precision('high')
|
| 25 |
torch.jit.script = lambda f: f
|
| 26 |
|
|
|
|
| 78 |
'General-legacy': 'BiRefNet-legacy'
|
| 79 |
}
|
| 80 |
|
|
|
|
|
|
|
|
|
|
| 81 |
# 초기 모델 로딩 (기본: General)
|
| 82 |
birefnet = AutoModelForImageSegmentation.from_pretrained(
|
| 83 |
+
'/'.join(('zhengpeng7', usage_to_weights_file['General'])),
|
| 84 |
trust_remote_code=True
|
| 85 |
)
|
| 86 |
birefnet.to(device)
|