from flask import Flask, request, jsonify, render_template import os from dotenv import load_dotenv load_dotenv() app = Flask(__name__) @app.route('/', methods=['GET', 'POST']) def upload_file(): if request.method == 'POST': txt_file = request.files['txt_file'] # Считываем строки из загруженного файла TXT lines = txt_file.read().decode().split(" ") # Создаем словарь в формате JSON json_data = {str(index+1): line.strip() for index, line in enumerate(lines)} # Записываем данные в файл JSON with open('output.json', 'w') as json_file: json_file.write(jsonify(json_data).get_data(as_text=True)) return render_template('index.html', json_data=json_data) return render_template('index.html') if __name__ == '__main__': app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))