unknown
fix
de7fe63
# app.py
from flask import Flask, render_template, request, send_file
import markdown
import os
from utils.markdown_to_docx import save_as_docx
from utils.markdown_to_pdf import save_as_pdf
# Set environment variables to ensure playwright finds Chromium
os.environ["PLAYWRIGHT_BROWSERS_PATH"] = "/usr/local/share/pw-browsers"
os.environ["PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD"] = "1"
app = Flask(__name__)
@app.route("/")
def index():
return render_template("index.html")
@app.route("/export", methods=["POST"])
def export():
md_text = request.form["markdown"]
export_type = request.form["type"] # 'docx' or 'pdf'
if export_type == "docx":
output_path = save_as_docx(md_text)
elif export_type == "pdf":
output_path = save_as_pdf(md_text)
else:
return "Unsupported format", 400
return send_file(output_path, as_attachment=True)
if __name__ == "__main__":
output_dir = "/tmp/output"
os.makedirs(output_dir, exist_ok=True)
port = int(os.environ.get("PORT", 7860))
app.run(host="0.0.0.0", port=port)