Commit
·
f8a8a2f
1
Parent(s):
0a20852
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,22 +3,18 @@ from flask import request, jsonify
|
|
| 3 |
import os
|
| 4 |
import json
|
| 5 |
from dotenv import load_dotenv
|
| 6 |
-
|
| 7 |
load_dotenv()
|
| 8 |
app = flask.Flask(__name__, template_folder="./")
|
| 9 |
app.config["DEBUG"] = True
|
| 10 |
-
|
| 11 |
@app.route('/')
|
| 12 |
def index():
|
| 13 |
return flask.render_template('index.html')
|
| 14 |
-
|
| 15 |
@app.route("/", methods=["POST"])
|
| 16 |
def predict():
|
| 17 |
incoming = request.get_json()
|
| 18 |
print(incoming)
|
| 19 |
# Ваша логика обработки текста здесь
|
| 20 |
return "Your response here"
|
| 21 |
-
|
| 22 |
@app.route("/avp", methods=["POST"])
|
| 23 |
def avp():
|
| 24 |
try:
|
|
@@ -28,11 +24,11 @@ def avp():
|
|
| 28 |
for key, value in incoming.items():
|
| 29 |
if isinstance(value, int):
|
| 30 |
if value > 0:
|
| 31 |
-
result[key] =
|
| 32 |
else:
|
| 33 |
-
result[key] =
|
| 34 |
else:
|
| 35 |
-
result[key] =
|
| 36 |
response = jsonify(result)
|
| 37 |
return response
|
| 38 |
except Exception as e:
|
|
@@ -40,6 +36,5 @@ def avp():
|
|
| 40 |
"error": str(e)
|
| 41 |
}
|
| 42 |
return jsonify(error_response), 500
|
| 43 |
-
|
| 44 |
if __name__ == '__main__':
|
| 45 |
app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))
|
|
|
|
| 3 |
import os
|
| 4 |
import json
|
| 5 |
from dotenv import load_dotenv
|
|
|
|
| 6 |
load_dotenv()
|
| 7 |
app = flask.Flask(__name__, template_folder="./")
|
| 8 |
app.config["DEBUG"] = True
|
|
|
|
| 9 |
@app.route('/')
|
| 10 |
def index():
|
| 11 |
return flask.render_template('index.html')
|
|
|
|
| 12 |
@app.route("/", methods=["POST"])
|
| 13 |
def predict():
|
| 14 |
incoming = request.get_json()
|
| 15 |
print(incoming)
|
| 16 |
# Ваша логика обработки текста здесь
|
| 17 |
return "Your response here"
|
|
|
|
| 18 |
@app.route("/avp", methods=["POST"])
|
| 19 |
def avp():
|
| 20 |
try:
|
|
|
|
| 24 |
for key, value in incoming.items():
|
| 25 |
if isinstance(value, int):
|
| 26 |
if value > 0:
|
| 27 |
+
result[key] = value - 1
|
| 28 |
else:
|
| 29 |
+
result[key] = 0
|
| 30 |
else:
|
| 31 |
+
result[key] = 0 # Если значение не является целым числом, присваиваем 0
|
| 32 |
response = jsonify(result)
|
| 33 |
return response
|
| 34 |
except Exception as e:
|
|
|
|
| 36 |
"error": str(e)
|
| 37 |
}
|
| 38 |
return jsonify(error_response), 500
|
|
|
|
| 39 |
if __name__ == '__main__':
|
| 40 |
app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))
|