amauricunha commited on
Commit
b6c7731
·
verified ·
1 Parent(s): c23a033

Update flask_app.py

Browse files
Files changed (1) hide show
  1. flask_app.py +29 -18
flask_app.py CHANGED
@@ -1,4 +1,4 @@
1
- #app.py
2
  import os
3
  import io
4
  import json
@@ -32,22 +32,30 @@ from study_planner import study_planner
32
  from admin_module import admin_manager, admin_required
33
 
34
  # --- CONFIGURAÇÃO INICIAL ---
35
- app = Flask(__name__)
36
-
37
- # Configuration for sessions
38
- app.config['SECRET_KEY'] = os.environ.get('SECRET_KEY', 'dev-key-change-in-production-hf-spaces')
39
- app.config['SESSION_TYPE'] = 'filesystem'
40
- app.config['SESSION_PERMANENT'] = False
41
- app.config['SESSION_USE_SIGNER'] = True
42
- app.config['SESSION_KEY_PREFIX'] = 'englishhelper:'
43
- app.config['PERMANENT_SESSION_LIFETIME'] = 86400 # 24 hours
44
-
45
- Session(app)
46
-
47
- # Print session config for debugging
48
- print(f"Session config - SECRET_KEY length: {len(app.config['SECRET_KEY'])}")
49
- print(f"Session config - SESSION_TYPE: {app.config['SESSION_TYPE']}")
50
- print(f"Session config - Working directory: {os.getcwd()}")
 
 
 
 
 
 
 
 
51
 
52
  # Ensure flask_session directory exists
53
  import os
@@ -1301,5 +1309,8 @@ def admin_interface():
1301
  def root():
1302
  return send_file('templates/index.html')
1303
 
 
1304
  if __name__ == '__main__':
1305
- app.run(host='0.0.0.0', port=7860)
 
 
 
1
+ # flask_app.py - English Helper Flask Application
2
  import os
3
  import io
4
  import json
 
32
  from admin_module import admin_manager, admin_required
33
 
34
  # --- CONFIGURAÇÃO INICIAL ---
35
+ # Evitar múltiplas instâncias do Flask
36
+ if 'app' not in globals():
37
+ app = Flask(__name__)
38
+
39
+ # Configuration for sessions
40
+ app.config['SECRET_KEY'] = os.environ.get('SECRET_KEY', 'dev-key-change-in-production-hf-spaces')
41
+ app.config['SESSION_TYPE'] = 'filesystem'
42
+ app.config['SESSION_PERMANENT'] = False
43
+ app.config['SESSION_USE_SIGNER'] = True
44
+ app.config['SESSION_KEY_PREFIX'] = 'englishhelper:'
45
+ app.config['PERMANENT_SESSION_LIFETIME'] = 86400 # 24 hours
46
+
47
+ # Configuração para HF Spaces
48
+ app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0 # Evitar cache de arquivos
49
+ app.config['TEMPLATES_AUTO_RELOAD'] = True
50
+
51
+ Session(app)
52
+
53
+ # Print session config for debugging
54
+ print(f"✅ Flask app inicializado - SECRET_KEY length: {len(app.config['SECRET_KEY'])}")
55
+ print(f"✅ Session config - SESSION_TYPE: {app.config['SESSION_TYPE']}")
56
+ print(f"✅ Working directory: {os.getcwd()}")
57
+ else:
58
+ print("✅ Flask app já existe - reutilizando instância")
59
 
60
  # Ensure flask_session directory exists
61
  import os
 
1309
  def root():
1310
  return send_file('templates/index.html')
1311
 
1312
+ # Evitar execução automática quando importado
1313
  if __name__ == '__main__':
1314
+ print("⚠️ flask_app.py executado diretamente")
1315
+ print("💡 Use app.py para HF Spaces ou execute como módulo")
1316
+ app.run(host='0.0.0.0', port=5000, debug=True)