Try this
if len(columns) == 2 and (type(columns[0]) == int or type(columns[0]) == float):
pie_ch = px.pie(df, values=columns[0], names=columns[1])
pie_ch.write_html("templates/visualization.html")
else:
print("Please select 2 features only & the first feature should be numerical")