How to find peaks & eliminate flat tops

yes, In my code if you look closely I use an algorithm for finding peak points. Thats not my issue... the flat tops are my issue, where they repeat and print each repeated value as a peak point which is false.. every example I observe does not contain flat tops so of course results are successful.