Spaces:
Runtime error
Runtime error
Commit ·
fd56604
1
Parent(s): a83ac8f
Update app.py
Browse files123234568789101112131516171814151617181920212223242526272829303132333435363738394041424344454647484950515253import flaskfrom flask import request, jsonifyfrom flask import send_filefrom flask import request, jsonify, send_fileimport osimport jsonfrom dotenv import load_dotenvload_dotenv()app = flask.Flask(__name__, template_folder="./")app = flask.Flask(__name__)app.config["DEBUG"] = True@app.route('/')def index(): return flask.render_template('index.html')@app.route("/", methods=["POST"])def predict(): incoming = request.get_json() print(incoming) # Ваша логика обработки текста здесь return "Your response here" try: incoming = request.get_json() print(incoming) # Ваша логика обработки текста здесь # ... # Формирование и возврат ответа в формате JSON response = { "message": "Response from server" } return jsonify(response) except Exception as e: error_response = { "error": str(e) } return jsonify(error_response), 500@app.route("/avp", methods=["POST"])def avp(): try: incoming = request.get_json() print(incoming) result = {} for key, value in incoming.items(): if int(value) > 0: result[key] = str(int(value) - 1) else: result[key] = value # Сохранение результата в файл with open("output.json", "w") as file: json.dump(result, file) # Возвращение файла клиенту return send_file("output.json", as_attachment=True) except Exception as e: error_response = { "error": str(e)app.py+23-7