Actually that would be pretty easy. Just need to run a microswitch inside of a small tube that is triggered by the filament on top of the extruder assembly, or on top of the machine as a filament guide.

If you wanted to get real fancy you can use a through beam, but why spend the money?

The automatic reloading of filament is something I gotta see though.