Believe it or not, this is a question composers and performers have asked themselves for centuries. In the world of baroque music, a common answer was to add melodic ornamentation and improvisation. This was most obvious in the Da Capo Aria.
When performing this ternary form, vocalists would usually sing the first two sections as written and then, on the repeat of the A section, would improvise stylish ornamentations. Singers, renown for their improvisational ability and vocal prowess, would often use this musical form as a platform to showcase virtuosic technique.
Centuries later, the idea of adding interest to a repeated section by improvising would become a basic tenet of jazz.
That’s a fair question and one that composers eventually asked after the vocal showcases of the Da Capo Aria got out of hand. Composers like Christoph Willibald Gluck sought to have performers only sing the written notes in his operas so that everyone could understand the words. Instead of the musicians improvising, it becomes the composer/arranger’s responsibility to keep the music interesting despite repetitions.
By adding some embellishments we can transform the melody while still maintaining it’s original character and sound.
An easy way to add embellishments is to make diatonic connections between the notes of the original melody. You can see this in the above example between the C on beat 1 of the first measure and G on beat 3 of the same measure, as well as the notes between the G on beat 4 of measure 1 and the F on beat 1 of measure 2.