Spaces:
Sleeping
Sleeping
Commit
·
63144e1
1
Parent(s):
3542be4
app.py
Browse files- utils/utils.py +22 -0
utils/utils.py
CHANGED
|
@@ -37,6 +37,28 @@ def load_cn_config(model_dir):
|
|
| 37 |
config_path = os.path.join(os.getcwd(), file_name)
|
| 38 |
shutil.copy(config_path, file_path)
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
|
| 42 |
def resize_image_aspect_ratio(image):
|
|
|
|
| 37 |
config_path = os.path.join(os.getcwd(), file_name)
|
| 38 |
shutil.copy(config_path, file_path)
|
| 39 |
|
| 40 |
+
def load_tagger_model(model_dir):
|
| 41 |
+
model_id = 'SmilingWolf/wd-swinv2-tagger-v3'
|
| 42 |
+
files = [
|
| 43 |
+
'config.json', 'model.onnx', 'selected_tags.csv', 'sw_jax_cv_config.json'
|
| 44 |
+
]
|
| 45 |
+
|
| 46 |
+
if not os.path.exists(model_dir):
|
| 47 |
+
os.makedirs(model_dir)
|
| 48 |
+
|
| 49 |
+
for file in files:
|
| 50 |
+
file_path = os.path.join(model_dir, file)
|
| 51 |
+
if not os.path.exists(file_path):
|
| 52 |
+
url = f'https://huggingface.co/{model_id}/resolve/main/{file}'
|
| 53 |
+
response = requests.get(url, allow_redirects=True)
|
| 54 |
+
if response.status_code == 200:
|
| 55 |
+
with open(file_path, 'wb') as f:
|
| 56 |
+
f.write(response.content)
|
| 57 |
+
print(f'Downloaded {file}')
|
| 58 |
+
else:
|
| 59 |
+
print(f'Failed to download {file}')
|
| 60 |
+
else:
|
| 61 |
+
print(f'{file} already exists.')
|
| 62 |
|
| 63 |
|
| 64 |
def resize_image_aspect_ratio(image):
|