File size: 1,661 Bytes
f18f04b
fd56604
f18f04b
 
 
 
fd56604
e91a221
f18f04b
 
 
 
 
fd56604
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f18f04b
 
e91a221
 
 
fd56604
7b0bd1e
e91a221
4af33dc
 
7b0bd1e
 
fd56604
9ba7b32
 
 
fd56604
9ba7b32
 
fd56604
e91a221
 
 
 
 
f18f04b
e91a221
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import flask
from flask import request, jsonify, send_file
import os
import json
from dotenv import load_dotenv
load_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)
        
        # Ваша логика обработки текста здесь
        # ...
        # Формирование и возврат ответа в формате JSON
        response = {
            "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)
        }
        return jsonify(error_response), 500
if __name__ == '__main__':
    app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))