from pathlib import Path
p=Path('/opt/struktur/social-media-agent/app.py'); s=p.read_text()
if 'from human_feedback import save_variant_feedback' not in s:
needle='from publish_ready import get_packages, decide_package, generate_package_image, valid_package_image_path, image_download_name, select_package_variant'
assert s.count(needle)==1; s=s.replace(needle,needle+'\nfrom human_feedback import save_variant_feedback')
marker='@app.route("/bereit/<package_id>/varianten/<variant_id>/auswaehlen", methods=["POST"])'
if 'def package_variant_feedback' not in s:
route='''@app.route("/bereit/<package_id>/varianten/<variant_id>/feedback", methods=["POST"])
def package_variant_feedback(package_id, variant_id):
try:
save_variant_feedback(package_id, variant_id, request.form.get("rating", ""), request.form.get("reason", ""), evaluated_by="Carlo")
except ValueError:
pass
return redirect(url_for("ready_packages"))
'''
assert s.count(marker)==1; s=s.replace(marker,route+marker)
p.write_text(s); print('feedback endpoint ready')