-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
48 lines (38 loc) · 1.3 KB
/
app.py
File metadata and controls
48 lines (38 loc) · 1.3 KB
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
import os
from flask import Flask
from flask_smorest import Api
from flask_cors import CORS
from dotenv import load_dotenv
from ml_model.model import train_model
from db import db
from resources.prediction import blp as PredictionBlueprint
def create_app(db_url=None):
app = Flask(__name__)
load_dotenv()
# Configurações básicas da API
app.config["API_TITLE"] = "Wine Prediction API"
app.config["API_VERSION"] = "v1"
app.config["OPENAPI_VERSION"] = "3.0.3"
app.config["OPENAPI_URL_PREFIX"] = "/"
app.config["OPENAPI_SWAGGER_UI_PATH"] = "/"
app.config["OPENAPI_SWAGGER_UI_URL"] = "https://cdn.jsdelivr.net/npm/swagger-ui-dist/"
app.config["SQLALCHEMY_DATABASE_URI"] = db_url or os.getenv("DATABASE_URL", "sqlite:///data.db")
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
app.config["PROPAGATE_EXCEPTIONS"] = True
# Inicialização do banco de dados
db.init_app(app)
# Configuração da API
api = Api(app)
# Enable CORS
CORS(app)
# Registro dos blueprints
api.register_blueprint(PredictionBlueprint)
# Criação das tabelas do banco de dados
with app.app_context():
db.create_all()
# Treinar e salvar o modelo
train_model()
return app
if __name__ == '__main__':
app = create_app()
app.run(debug=True)