bananwisheyes's picture
Upload 23 files
60c107d verified
from flask import Flask, request, send_file, render_template
from main import create_docx_from_text
import os
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/process', methods=['POST'])
def process():
try:
user_text = request.form['text']
create_docx_from_text(user_text)
output_path = os.path.abspath("output.docx")
print("📄 Абсолютный путь к файлу:", output_path)
if not os.path.exists(output_path):
raise FileNotFoundError(f"Файл не найден: {output_path}")
return send_file(output_path, as_attachment=True, download_name="output.docx")
except Exception as e:
print("❌ Ошибка при обработке текста:", str(e))
return f"Ошибка при обработке текста: {str(e)}", 500
if __name__ == '__main__':
app.run(debug=True)