Hello! Could someone please give me an explanation about why in the above lick they use G flat (yellow square) instead of G and an E (red circle) instead of E flat, as the Gm dictates?
Thank you in advance!
You could ask the same about the A note. All three are just passing notes, passing from one 'good' note to another 'good' note. I call them stepping stone notes. They come on unstressed parts of the bar. The stressed points usually being beats 1 and 3. Here the A is & of 1, Gb & of 3 and E & of 4, all weak points where almost any note will not sound too bad. Gb>F>E is a chromatic run, possibly ending on a chord tone on the important 1 in the next bar, Eb perhaps, part of Cm chord? All this presumes it's in key C, with the C key sig - no # or b.
The 'Gm7' dictates nothing. Except that's the chord appropriate in that bar. There's no 'rules' (as we keep saying!); there's only 'theory'. Often in a bar of Gm7 there will be some chord tones - G, Bb, D, F, but that certainly does not preclude use of any of the remaining eight notes, whatever key the piece happens to be in. That concept you (and so many others) adhere to is wrong!
In general, not every note needs to be considered part of the harmony. You can have notes outside of a chord or key be utilized. Both of these notes are examples of non harmonic tones.
The G♭ is a chromatic passing tone. It is sandwiched between the G and F which are both chord tones. The E is also most likely another non harmonic tone, what it is exactly depends on what comes next. It could be another chromatic passing tone if the next note is an E♭, it could just as easily be an anticipation of what is next especially if you are in the key of A minor or C major which the lack of accidentals in the key signature.
Although for this particular phrase the easiest explanation is "they're simply passing notes" it's worth noting these particular passing notes are a bit like a magic ingredient in the sound of jazz as they are part of jazz minor scale, almost a classic sound in jazz.
So if you start digging more and analyzing jazz recordings you will come across phrases where the sixth and major seventh over minor chords function as a static tension or a harmonic "color" that doesn't really get resolved.
Context is important when trying to understand what the chords are doing, but the Gm7 could be a ii chord, perhaps part of a ii-V7-I progression. The Dorian scale is often used to create phrases over ii chords, and G Dorian includes an E, not an Eb. In fact, the natural sixth degree (the E) is the note that gives Dorian its character.
In this interpretation, the only other note that needs explaining is the Gb. It is, of course, just a chromatic passing note. But more can be said. Bebop players used to add certain chromatic passing notes to smooth out their phrases; this phrase can be seen as constructed from the G Bebop Dorian scale, with a Gb written in place of F#.
In other words, this phrase is typical of what might be played over a ii chord in the Bebop idiom.
The technical term is non-chord tones.
The other answers already explain these particular NCT's are unaccented passing tones, but there is a complete nomenclature of NCT from classical music that you should review to see the wide range of possibilities. In homophonic (chord based) music a huge amount of melody can be explain as the interplay of chord tones following the harmony and non-chord tones.
In jazz there is a special type of NCT called an enclosure which you should also review.
The chord/scale system in jazz is an alternate approach from the classical non-chord tones theory. But some other questions/answers here at StackExchange explain that historically - prior to the chord/scale system - jazz improv was largely arpeggiated chords embellished with non-chord tones. The two systems shouldn't be considered mutually exclusive.
You might want to expand this single question to a general review of the whole topic of non-chord tones. It will deepen your understanding of melody.