Functions are the general way to reduce code duplication. This case isn't any different. You just need to to define a function to implement your `while read` logic.
myfunc() {
while read LINE
do
prog_1
prog_2
...
prog_n
done
}
if [[ -t 0 ]]; then
myfunc # read stdin passed to the script
else
myfunc < "$1" # redirect file to stdin
fi