Where did Rebbi Akiva find the inspiration to pick himself up and teach students again after losing 24,000 students?
See Yevamot 62b. The juxtaposition of the sentences in Gemara leads to understand that he learned this from a verse (Ecclesiastes 11.6).
ר"ע אומר למד תורה בילדותו ילמוד תורה בזקנותו היו לו תלמידים בילדותו יהיו לו תלמידים בזקנותו שנא' בבקר זרע את זרעך וגו' אמרו שנים עשר אלף זוגים תלמידים היו לו לרבי עקיבא מגבת עד אנטיפרס וכולן מתו בפרק אחד מפני שלא נהגו כבוד זה לזה והיה העולם שמם עד שבא ר"ע אצל רבותינו שבדרום ושנאה להם ר"מ ור' יהודה ור' יוסי ורבי שמעון ורבי אלעזר בן שמוע והם הם העמידו תורה אותה שעה
Grandchildren are considered like children... Rabbi Akiva says that the verse should be understood as follows: If one studied Torah in his youth he should study more Torah in his old age; if he had students in his youth he should have additional students in his old age, as it is stated: “In the morning sow your seed, etc.”(1) They said by way of example that Rabbi Akiva had twelve thousand pairs of students in an area of land that stretched from Gevat to Antipatris in Judea, and they all died in one period of time, because they did not treat each other with respect. And the world was desolate of Torah until Rabbi Akiva came to our Rabbis in the South and taught his Torah to them. This second group of disciples consisted of Rabbi Meir, Rabbi Yehuda, Rabbi Yosei, Rabbi Shimon, and Rabbi Elazar ben Shamua. And these are the very ones who upheld the study of Torah at that time.
Although Rabbi Akiva’s earlier students did not survive, his later disciples were able to transmit the Torah to future generations. With regard to the twelve thousand pairs of Rabbi Akiva’s students, the Gemara adds: It is taught that all of them died in the period from Passover until Shavuot.
(1): Ecclesiastes 11.6
בַּבֹּ֙קֶר֙ זְרַ֣ע אֶת־זַרְעֶ֔ךָ וְלָעֶ֖רֶב אַל־תַּנַּ֣ח יָדֶ֑ךָ כִּי֩ אֵֽינְךָ֨ יוֹדֵ֜עַ אֵ֣י זֶ֤ה יִכְשָׁר֙ הֲזֶ֣ה אוֹ־זֶ֔ה וְאִם־שְׁנֵיהֶ֥ם כְּאֶחָ֖ד טוֹבִֽים׃
In the morning sow your seed, and in the evening do not withhold your hand; for you do not know which shall prosper, either this or that, or whether they both alike shall be good.