Spaces:
Sleeping
Sleeping
File size: 2,104 Bytes
c8e1e67 3620488 c8e1e67 3620488 c8e1e67 3620488 c8e1e67 3620488 c8e1e67 3620488 c8e1e67 3620488 c8e1e67 3620488 c8e1e67 3620488 c8e1e67 3620488 c8e1e67 3620488 c8e1e67 3620488 c8e1e67 3620488 c8e1e67 3620488 c8e1e67 3620488 c8e1e67 3620488 | 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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | from flask import Flask, render_template, request, jsonify
from flask_cors import CORS
from utils.predictor import CricketPredictor
from utils.encoders import TEAMS, VENUES
import logging
import os
app = Flask(__name__)
CORS(app)
logging.basicConfig(level=logging.INFO)
predictor = CricketPredictor()
# βββββββββββββ ROUTES βββββββββββββ
@app.route("/")
def index():
return render_template("index.html", teams=TEAMS, venues=VENUES)
@app.route("/simulate")
def simulate():
return render_template("simulate.html", teams=TEAMS, venues=VENUES)
@app.route("/model-info")
def model_info():
return render_template("model_info.html")
# βββββββββββββ API βββββββββββββ
@app.route("/api/predict", methods=["POST"])
def api_predict():
try:
data = request.get_json(force=True)
required = [
"batting_team", "bowling_team", "venue",
"innings", "over", "ball_in_over",
"current_score", "wickets_fallen"
]
missing = [f for f in required if f not in data]
if missing:
return jsonify({"error": f"Missing: {', '.join(missing)}"}), 400
# Defaults
data.setdefault("batter_sr", 130)
data.setdefault("bowler_eco", 7.5)
data.setdefault("last_6_runs", 6)
data.setdefault("last_12_runs", 12)
if int(data["innings"]) == 2:
if "balls_remaining" not in data:
return jsonify({"error": "balls_remaining required"}), 400
result = predictor.predict(data)
return jsonify({"success": True, "prediction": result})
except Exception as e:
logging.exception("Prediction error")
return jsonify({"error": str(e)}), 500
@app.route("/api/health")
def health():
return jsonify({"status": "ok"})
# βββββββββββββ RUN βββββββββββββ
if __name__ == "__main__":
port = int(os.environ.get("PORT", 7860))
app.run(host="0.0.0.0", port=port, debug=True) |