Filing for bankruptcy does not mean losing your apartment. As long as you have remained up to date on your rent payments, you can continue to live in your apartment, according to the conditions stated in your lease or by the common-law of landlord-tenant relations. If the lease ended before you filed for bankruptcy, however, this may not be the case.
However, technically speaking, your lease that has not expired is an asset of your bankruptcy estate without any value, and consequently it would probably be rejected by the Chapter 7 trustee. This rejection is a breach in the lease, and would be sufficient grounds for the landlord to evict you. If this seems like a possibility, you should speak with your bankruptcy trustee, who can officially “abandon” the lease, thus allowing you to officially affirm it.