Spaces:
Running
Running
Commit
·
6bf3da5
1
Parent(s):
a263477
Añadir descarga automática de modelos y actualizar configuración
Browse files- download_models.py +46 -0
download_models.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import requests
|
| 3 |
+
import shutil
|
| 4 |
+
|
| 5 |
+
def download_file(url, save_path):
|
| 6 |
+
"""Descarga un archivo desde una URL y lo guarda en la ruta especificada."""
|
| 7 |
+
print(f"Descargando {url} a {save_path}...")
|
| 8 |
+
|
| 9 |
+
response = requests.get(url, stream=True)
|
| 10 |
+
if response.status_code == 200:
|
| 11 |
+
with open(save_path, 'wb') as f:
|
| 12 |
+
shutil.copyfileobj(response.raw, f)
|
| 13 |
+
print(f"Archivo descargado exitosamente: {save_path}")
|
| 14 |
+
return True
|
| 15 |
+
else:
|
| 16 |
+
print(f"Error al descargar {url}: {response.status_code}")
|
| 17 |
+
return False
|
| 18 |
+
|
| 19 |
+
def main():
|
| 20 |
+
# Crear directorio para modelos si no existe
|
| 21 |
+
models_dir = "models"
|
| 22 |
+
if not os.path.exists(models_dir):
|
| 23 |
+
os.makedirs(models_dir)
|
| 24 |
+
print(f"Directorio creado: {models_dir}")
|
| 25 |
+
|
| 26 |
+
# URLs y rutas para los modelos necesarios
|
| 27 |
+
models = [
|
| 28 |
+
{
|
| 29 |
+
"url": "https://raw.githubusercontent.com/opencv/opencv/master/samples/dnn/face_detector/deploy.prototxt",
|
| 30 |
+
"path": os.path.join(models_dir, "deploy.prototxt")
|
| 31 |
+
},
|
| 32 |
+
{
|
| 33 |
+
"url": "https://raw.githubusercontent.com/opencv/opencv_3rdparty/dnn_samples_face_detector_20170830/res10_300x300_ssd_iter_140000.caffemodel",
|
| 34 |
+
"path": os.path.join(models_dir, "res10_300x300_ssd_iter_140000.caffemodel")
|
| 35 |
+
}
|
| 36 |
+
]
|
| 37 |
+
|
| 38 |
+
# Descargar cada modelo
|
| 39 |
+
for model in models:
|
| 40 |
+
if not os.path.exists(model["path"]):
|
| 41 |
+
download_file(model["url"], model["path"])
|
| 42 |
+
else:
|
| 43 |
+
print(f"El archivo ya existe: {model['path']}")
|
| 44 |
+
|
| 45 |
+
if __name__ == "__main__":
|
| 46 |
+
main()
|