Gettin error when trying to test "Gernerate Music"

Hi together,
i am a new member, and am new to Python and such stuff.

I successfully tested the Zalando-piece teaching a NN to select the clothings. Worked very well.

My interest for seaching for AI is music, so i tried the “Generate Music with an RNN” as next sample.

It worked well, but when defining the function “def midi_to_notes(midi_file: str) → pd.DataFrame:” i get an ident-error, and i am not able to find the error.

Does anyone have used this example and has a solution?

Thanks for your answers!

Greetings

Hartmut (Tutorius)

Here the code and the results:

Code to be copied inside python: (Taken from צור מוזיקה עם RNN  |  TensorFlow Core )

def midi_to_notes(midi_file: str) -> pd.DataFrame:
  pm = pretty_midi.PrettyMIDI(midi_file)
  instrument = pm.instruments[0]
  notes = collections.defaultdict(list)

  # Sort the notes by start time
  sorted_notes = sorted(instrument.notes, key=lambda note: note.start)
  prev_start = sorted_notes[0].start

  for note in sorted_notes:
    start = note.start
    end = note.end
    notes['pitch'].append(note.pitch)
    notes['start'].append(start)
    notes['end'].append(end)
    notes['step'].append(start - prev_start)
    notes['duration'].append(end - start)
    prev_start = start

  return pd.DataFrame({name: np.array(value) for name, value in notes.items()})

Errors in python-konsole:

>>> def midi_to_notes(midi_file: str) -> pd.DataFrame:
...   pm = pretty_midi.PrettyMIDI(midi_file)
...   instrument = pm.instruments[0]
...   notes = collections.defaultdict(list)
... 
>>>   # Sort the notes by start time
>>>   sorted_notes = sorted(instrument.notes, key=lambda note: note.start)
  File "<stdin>", line 1
    sorted_notes = sorted(instrument.notes, key=lambda note: note.start)
IndentationError: unexpected indent
>>>   prev_start = sorted_notes[0].start
  File "<stdin>", line 1
    prev_start = sorted_notes[0].start
IndentationError: unexpected indent
>>> 
>>>   for note in sorted_notes:
  File "<stdin>", line 1
    for note in sorted_notes:
IndentationError: unexpected indent
>>>     start = note.start
  File "<stdin>", line 1
    start = note.start
IndentationError: unexpected indent
>>>     end = note.end
  File "<stdin>", line 1
    end = note.end

Hi,
Make sure there are not TABS in the indentatios in the source code. Replace them by spaces.
Hope this help.