DmitrMakeev commited on
Commit
e91a221
·
1 Parent(s): 89cab91

Update app.py

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