This is known as König's Theorem (there is also a lemma called the son of this one). We are going to assume the axiom of choice through this answer, otherwise one cannot prove this theorem (more on that at the bottom).
Michael Greinecker gave a concise argument for the fact there is no surjective function from the union to the product. Which under the axiom of choice is enough to conclude there is a surjection in the other direction, and an injection from the union to the product, as wanted. Here is a more explicit construction of an injection:
If any of the $A_i$ is empty let us drop it from the list, and remove the corresponding $B_i$ as well. I hope it's clear why this is not going to harm the result. We may also assume that the $A_i$'s are pairwise disjoint sets.
The fact that $|A_i|<|B_i|$ means that there is an injection $f_i\colon A_i\to B_i$. And there is no injection in the other direction, else by Cantor-Bernstein we would have equality rather than a sharp inequality. For simplicity we can also assume that $A_i\subsetneqq B_i$ for all $i\in I$.
Fix $\langle b_i\mid i\in I\rangle$ some sequence in the product. Let us define an injection now. Let $a\in A_j$, if $a\neq b_j$ then send $a$ to the sequence $\langle \overline b_i\mid i\in I\rangle$ such that $\overline b_i=b_i$ for $i\neq j$ and $a$ otherwise.
If $a=b_j$, we know that $B_i$ has at least two elements for every $i\in I$ then we can fix $\langle c_i\mid i\in I\rangle$ in the product, such that $c_i\neq b_i$ for every $i\in I$. So in the case $a=b_j$ we send $a$ to the sequence of $\langle \overline c_i\mid i\in I\rangle$ such that $\overline c_i=c_i$ for $i\neq j$, and $a$ otherwise.
It is not hard to see that this is an injective function. Therefore the union has cardinality less or equal than that of the product.
A word about the axiom of choice. It is consistent that without the axiom of choice there is a countable set of disjoint pairs that has no choice function. Namely $\{P_n\mid n\in\omega\}$ such that $\prod P_n=\varnothing$. It is easy to see that even if we take $A_n=\{0\}$ for all $n$, then $|A_n|=1<2=|P_n|$, and $\left|\bigcup A_n\right| = |\{0\}| = 1 > 0 = |\varnothing| =\left|\prod P_n\right|$
I will remark, however, that if we assume that $A_i$ and $B_i$ are all sets of ordinals then the lemma holds regardless to the axiom of choice.