Spaces:
Runtime error
Runtime error
Commit ·
fd56604
1
Parent(s): a83ac8f
Update app.py
Browse files12345678910111213141516171819202122232425262728293031323334353637import flaskfrom flask import request, jsonifyfrom flask import send_fileimport osimport jsonfrom dotenv import load_dotenvload_dotenv()app = flask.Flask(__name__, template_folder="./")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"@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)1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253import flaskfrom flask import request, jsonify, send_fileimport osimport jsonfrom dotenv import load_dotenvload_dotenv()app = flask.Flask(__name__)app.config["DEBUG"] = True@app.route('/')def index():return flask.render_template('index.html')@app.route("/", methods=["POST"])def predict():try:incoming = request.get_json()print(incoming)# Ваша логика обработки текста здесь# ...# Формирование и возврат ответа в формате JSONresponse = {"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