Commit
·
fd56604
1
Parent(s):
a83ac8f
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,37 +1,53 @@
|
|
| 1 |
import flask
|
| 2 |
-
from flask import request, jsonify
|
| 3 |
-
from flask import send_file
|
| 4 |
import os
|
| 5 |
import json
|
| 6 |
from dotenv import load_dotenv
|
| 7 |
load_dotenv()
|
| 8 |
-
app = flask.Flask(__name__
|
| 9 |
app.config["DEBUG"] = True
|
| 10 |
@app.route('/')
|
| 11 |
def index():
|
| 12 |
return flask.render_template('index.html')
|
| 13 |
@app.route("/", methods=["POST"])
|
| 14 |
def predict():
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
@app.route("/avp", methods=["POST"])
|
| 20 |
def avp():
|
| 21 |
try:
|
| 22 |
incoming = request.get_json()
|
| 23 |
print(incoming)
|
|
|
|
| 24 |
result = {}
|
| 25 |
for key, value in incoming.items():
|
| 26 |
if int(value) > 0:
|
| 27 |
result[key] = str(int(value) - 1)
|
| 28 |
else:
|
| 29 |
result[key] = value
|
|
|
|
| 30 |
# Сохранение результата в файл
|
| 31 |
with open("output.json", "w") as file:
|
| 32 |
json.dump(result, file)
|
|
|
|
| 33 |
# Возвращение файла клиенту
|
| 34 |
return send_file("output.json", as_attachment=True)
|
|
|
|
| 35 |
except Exception as e:
|
| 36 |
error_response = {
|
| 37 |
"error": str(e)
|
|
|
|
| 1 |
import flask
|
| 2 |
+
from flask import request, jsonify, send_file
|
|
|
|
| 3 |
import os
|
| 4 |
import json
|
| 5 |
from dotenv import load_dotenv
|
| 6 |
load_dotenv()
|
| 7 |
+
app = flask.Flask(__name__)
|
| 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 |
+
try:
|
| 15 |
+
incoming = request.get_json()
|
| 16 |
+
print(incoming)
|
| 17 |
+
|
| 18 |
+
# Ваша логика обработки текста здесь
|
| 19 |
+
# ...
|
| 20 |
+
# Формирование и возврат ответа в формате JSON
|
| 21 |
+
response = {
|
| 22 |
+
"message": "Response from server"
|
| 23 |
+
}
|
| 24 |
+
return jsonify(response)
|
| 25 |
+
|
| 26 |
+
except Exception as e:
|
| 27 |
+
error_response = {
|
| 28 |
+
"error": str(e)
|
| 29 |
+
}
|
| 30 |
+
return jsonify(error_response), 500
|
| 31 |
@app.route("/avp", methods=["POST"])
|
| 32 |
def avp():
|
| 33 |
try:
|
| 34 |
incoming = request.get_json()
|
| 35 |
print(incoming)
|
| 36 |
+
|
| 37 |
result = {}
|
| 38 |
for key, value in incoming.items():
|
| 39 |
if int(value) > 0:
|
| 40 |
result[key] = str(int(value) - 1)
|
| 41 |
else:
|
| 42 |
result[key] = value
|
| 43 |
+
|
| 44 |
# Сохранение результата в файл
|
| 45 |
with open("output.json", "w") as file:
|
| 46 |
json.dump(result, file)
|
| 47 |
+
|
| 48 |
# Возвращение файла клиенту
|
| 49 |
return send_file("output.json", as_attachment=True)
|
| 50 |
+
|
| 51 |
except Exception as e:
|
| 52 |
error_response = {
|
| 53 |
"error": str(e)
|