OUAREDAEK commited on
Commit
313188d
Β·
verified Β·
1 Parent(s): 410a611

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +32 -9
app.py CHANGED
@@ -1,16 +1,37 @@
1
- import json
 
2
  import os
 
3
  from datetime import datetime
4
- from flask import Flask, render_template, request, jsonify
5
 
6
- # --- CONFIG ---
7
- PORT = int(os.environ.get("PORT", 7860)) # πŸ”‘ HF uses 7860
 
 
 
 
 
 
 
8
 
9
- app = Flask(__name__, template_folder="templates")
10
 
 
 
 
 
 
 
 
 
 
11
  STATS_FILE = "data/trust_stats.json"
12
 
 
13
 
 
 
 
14
  @app.route("/")
15
  def index():
16
  return render_template("index.html")
@@ -42,12 +63,14 @@ def save_trust():
42
 
43
  return jsonify({"status": "ok"})
44
 
45
-
 
 
46
  if __name__ == "__main__":
47
- print(f"πŸš€ Application lancΓ©e sur http://0.0.0.0:{PORT}")
48
  app.run(
49
- host="0.0.0.0", # πŸ”‘ required for Docker
50
- port=PORT, # πŸ”‘ 7860 for HF
51
  debug=False,
52
  use_reloader=False
53
  )
 
1
+ import subprocess
2
+ import sys
3
  import os
4
+ import json
5
  from datetime import datetime
 
6
 
7
+ # --------------------------------------------------
8
+ # πŸ”§ Auto-install required packages if missing
9
+ # --------------------------------------------------
10
+ def install_if_missing(package):
11
+ try:
12
+ __import__(package)
13
+ except ImportError:
14
+ print(f"⚑ Installing missing package: {package}")
15
+ subprocess.check_call([sys.executable, "-m", "pip", "install", package])
16
 
17
+ install_if_missing("flask")
18
 
19
+ # --------------------------------------------------
20
+ # πŸ“¦ Imports AFTER installation
21
+ # --------------------------------------------------
22
+ from flask import Flask, render_template, request, jsonify
23
+
24
+ # --------------------------------------------------
25
+ # βš™οΈ CONFIG
26
+ # --------------------------------------------------
27
+ PORT = int(os.environ.get("PORT", 7860)) # Hugging Face uses 7860
28
  STATS_FILE = "data/trust_stats.json"
29
 
30
+ app = Flask(__name__, template_folder="templates")
31
 
32
+ # --------------------------------------------------
33
+ # 🌐 Routes
34
+ # --------------------------------------------------
35
  @app.route("/")
36
  def index():
37
  return render_template("index.html")
 
63
 
64
  return jsonify({"status": "ok"})
65
 
66
+ # --------------------------------------------------
67
+ # πŸš€ Main
68
+ # --------------------------------------------------
69
  if __name__ == "__main__":
70
+ print(f"πŸš€ Application running on http://0.0.0.0:{PORT}")
71
  app.run(
72
+ host="0.0.0.0", # required for Docker
73
+ port=PORT, # 7860 for HF
74
  debug=False,
75
  use_reloader=False
76
  )