Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
|
@@ -1,29 +1,48 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import logging
|
| 3 |
-
from modules.api import AkiraAPI
|
| 4 |
-
import modules.config as config
|
| 5 |
-
|
| 6 |
-
# Configuração de logging
|
| 7 |
-
logging.basicConfig(level=logging.INFO, format='%(asctime)s [%(levelname)s] %(message)s')
|
| 8 |
-
logger = logging.getLogger(__name__)
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
def create_app():
|
| 12 |
-
akira = AkiraAPI(config)
|
| 13 |
-
return akira.app
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
app = create_app()
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
#
|
| 20 |
-
@app.route('/
|
| 21 |
-
def
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import logging
|
| 3 |
+
from modules.api import AkiraAPI
|
| 4 |
+
import modules.config as config
|
| 5 |
+
|
| 6 |
+
# Configuração de logging
|
| 7 |
+
logging.basicConfig(level=logging.INFO, format='%(asctime)s [%(levelname)s] %(message)s')
|
| 8 |
+
logger = logging.getLogger(__name__)
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def create_app():
|
| 12 |
+
akira = AkiraAPI(config)
|
| 13 |
+
return akira.app
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
app = create_app()
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Rota raiz para garantir que o HF detecte o app como "healthy"
|
| 20 |
+
@app.route('/')
|
| 21 |
+
def index():
|
| 22 |
+
return "Akira IA está online e pronta! Use /akira para interagir.", 200
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
# Health check explícito (usado pelo HF e por você)
|
| 26 |
+
@app.route('/health')
|
| 27 |
+
def health():
|
| 28 |
+
logger.info("Health check accessed.")
|
| 29 |
+
return "OK", 200
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
if __name__ == "__main__":
|
| 33 |
+
logger.info("Starting Akira IA Flask app...")
|
| 34 |
+
|
| 35 |
+
# Porta padrão do Hugging Face Spaces é 7860
|
| 36 |
+
port = int(os.getenv("PORT", 7860))
|
| 37 |
+
|
| 38 |
+
# Debug desativado em produção (HF Spaces)
|
| 39 |
+
debug_mode = os.getenv("FLASK_DEBUG", "False").lower() == "true"
|
| 40 |
+
|
| 41 |
+
logger.info(f"Running on port {port}, debug={'ON' if debug_mode else 'OFF'}")
|
| 42 |
+
|
| 43 |
+
app.run(
|
| 44 |
+
debug=debug_mode,
|
| 45 |
+
host="0.0.0.0",
|
| 46 |
+
port=port,
|
| 47 |
+
use_reloader=False # Evita restart duplo no HF
|
| 48 |
+
)
|