DmitrMakeev commited on
Commit
fbd677a
·
1 Parent(s): 37f93c6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -9
app.py CHANGED
@@ -2,33 +2,35 @@ import flask
2
  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
 
22
- response = {
23
- "bazis": {}
24
- }
25
-
26
- for key, value in incoming.items():
27
- if value == 0:
28
- response["bazis"][key] = 0
29
- elif value > 0:
30
- response["bazis"][key] = value - 1
31
 
32
  return jsonify(response)
 
33
  if __name__ == '__main__':
34
  app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))
 
2
  from flask import request, jsonify
3
  import os
4
  import json
5
+ import pandas as pd
6
  from dotenv import load_dotenv
7
  load_dotenv()
8
+
9
  app = flask.Flask(__name__, template_folder="./")
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
  incoming = request.get_json()
25
  print(incoming)
26
 
27
+ # Изменение значений JSON-файла
28
+ data = pd.DataFrame.from_dict(incoming, orient='index', columns=['value'])
29
+ data['value'] -= 1
30
+ data.loc[data['value'] < 0, 'value'] = 0
31
+ response = data.to_dict()['value']
 
 
 
 
32
 
33
  return jsonify(response)
34
+
35
  if __name__ == '__main__':
36
  app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))