Advertisement
s_ff

Untitled

Jun 27th, 2025
550
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.52 KB | None | 0 0
  1. set -euo pipefail
  2. IMGDIR="imagenes"
  3. if [ ! -d "$IMGDIR" ]; then
  4.   echo "no se encontro el directorio '$IMGDIR'"
  5.   echo "crea la carpeta y llamala imagenes"
  6.   exit 1
  7. fi
  8.  
  9. # haces los json si no existen
  10. [ -f etiquetas.json ] || echo "{}" > etiquetas.json
  11. [ -f imagenes.json ]  || echo "{}" > imagenes.json
  12.  
  13. # recorre cada archivo de imagen en el directorio
  14. for img in "${IMGDIR}"/*.{jpg,jpeg,png}; do
  15.   [ -f "$img" ] || continue
  16.   filename=$(basename "$img")
  17.   echo "Procesando $filename …"
  18.   # el yolo ese
  19.   yolo_out=$(yolo predict source="$img" 2>&1)
  20.   info_line=$(printf "%s\n" "$yolo_out" | grep 'image 1/1')
  21.   if echo "$info_line" | grep -q "(no detections)"; then
  22.     tags="no_detections"
  23.   else
  24.     raw_tags=$(printf "%s\n" "$info_line" \
  25.       | sed -E 's/.*[0-9]+x[0-9]+ (.*): [0-9]+.*$/\1/')
  26.     tags=$(printf "%s\n" "$raw_tags" | sed -E 's/[0-9]+ //g')
  27.   fi
  28.   # agregas la ruta al json para cada una
  29.   IFS=',' read -ra TAG_ARR <<< "$tags"
  30.   for tag in "${TAG_ARR[@]}"; do
  31.     tag=$(echo "$tag" | xargs)  # cortas
  32.     jq --arg t "$tag" --arg p "${IMGDIR}/${filename}" \
  33.       '.[$t] = (.[$t] // []) + [$p]' \
  34.       etiquetas.json > etiquetas.tmp.json \
  35.       && mv etiquetas.tmp.json etiquetas.json
  36.   done
  37.   # el moondream ese
  38.   desc=$(ollama run moondream "{'content':'Describe me this image','images':'$img'}" 2>&1 | tail -n1)
  39.   jq --arg k "$filename" --arg d "$desc" \
  40.     '.[$k] = $d' \
  41.     imagenes.json > imagenes.tmp.json \
  42.     && mv imagenes.tmp.json imagenes.json
  43. done
  44. echo "ok funciona todo"
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement