PHILADELPHIA — A Victorian-era dye factory is taking on a new role to help this city’s troubled public school system attract and retain teachers.

Two redbrick buildings in the up-and-coming but still gritty South Kensington section of Philadelphia are being converted into apartments and offices intended to house teachers and nonprofit educational organizations in what the developers hope will become a cohesive community.

When the renovation is complete, 60 percent of the buildings’ 114 apartments will be reserved for teachers, who will be offered a 25 percent discount on market rent — paying about $1,000 a month for a one-bedroom unit in a neighborhood where they typically rent for $1,300.

The remaining apartments will be available to the public. In addition, a quarter of the 160,000-square-foot space is being turned into offices for education-related nonprofit groups like Teach for America, which will use 10,000 square feet of renovated space as its regional headquarters.