Skip to content

Instantly share code, notes, and snippets.

@iamironz
Created December 9, 2023 14:51
Show Gist options
  • Save iamironz/1d7bea67f3e8b5a252230005269473f6 to your computer and use it in GitHub Desktop.
Save iamironz/1d7bea67f3e8b5a252230005269473f6 to your computer and use it in GitHub Desktop.
imagetotextclient.sh
#!/bin/bash
SERVER_IP="192.168.1.191"
SERVER_PORT="5000"
SERVER_URL="http://${SERVER_IP}:${SERVER_PORT}/process"
send_image() {
local image_path=$1
echo "Sending ${image_path} to ${SERVER_URL}"
curl -X POST -F "images=@${image_path}" "${SERVER_URL}"
}
send_directory() {
local directory_path=$1
echo "Sending all images in ${directory_path} to ${SERVER_URL}"
while IFS= read -r image_path; do
if [[ -f "$image_path" ]]; then
send_image "$image_path"
fi
done < <(find "$directory_path" -type f | sort -V)
}
main() {
local input_path=$1
if [[ -z "$input_path" ]]; then
echo "Usage: $0 <path_to_image_or_directory>"
exit 1
fi
if [[ -d "$input_path" ]]; then
send_directory "$input_path"
elif [[ -f "$input_path" ]]; then
send_image "$input_path"
else
echo "The path provided is neither a file nor a directory"
exit 1
fi
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment