I've heard of using walnuts to remove scratches on wooden furniture. Are there any plants that can be grown or foraged that have the ability to remove dirt/stains from carpets?
Vinegar is known to be a cleaning agent, but I don't know what sort of stains or what sort of carpet, so it is hard to know if it would be appropriate in your circumstance. You can make homemade vinegar a number of ways, but my method of choice is a long-standing batch of kombucha. If I were in your shoes, I might produce a good strong kombucha vinegar, then remove it from the SCOBY, filter nicely, let a bunch of lemon rinds soak in it for several days, then TRY IT on an inconspicuous section of the carpet to see if removes stains without destroying the color/material.