Kabila22 commited on
Commit
8fb3705
·
1 Parent(s): b77e974

backend commit

Browse files
Files changed (1) hide show
  1. app/main.py +12 -4
app/main.py CHANGED
@@ -22,7 +22,7 @@ if not GROQ_API_KEY:
22
  logger.error("GROQ_API_KEY not found in environment variables.")
23
  raise Exception("GROQ_API_KEY not found in environment variables.")
24
 
25
- # Log and clear proxy environment variables to avoid 'proxies' error
26
  logger.info(f"HTTP_PROXY: {os.environ.get('HTTP_PROXY')}")
27
  logger.info(f"HTTPS_PROXY: {os.environ.get('HTTPS_PROXY')}")
28
  os.environ.pop("HTTP_PROXY", None)
@@ -40,10 +40,10 @@ except Exception as e:
40
 
41
  app = FastAPI()
42
 
43
- # Enable CORS to allow frontend communication
44
  app.add_middleware(
45
  CORSMiddleware,
46
- allow_origins=["*"], # Adjust to specific frontend URL in production
47
  allow_credentials=True,
48
  allow_methods=["*"],
49
  allow_headers=["*"],
@@ -76,15 +76,23 @@ goals_df['y_coord'] = np.random.uniform(20, 80, len(goals_df)).round()
76
  teams = set(matches_df['home_team'].unique()).union(set(matches_df['away_team'].unique()))
77
  players = sorted([str(scorer) for scorer in goals_df['scorer'].dropna().unique() if pd.notna(scorer)])
78
 
 
79
  try:
 
80
  logistic_model = joblib.load('model/logistic_regression_model.pkl')
 
81
  linear_model_team1 = joblib.load('model/linear_regression_team1_goals.pkl')
 
82
  linear_model_team2 = joblib.load('model/linear_regression_team2_goals.pkl')
 
83
  le = joblib.load('model/label_encoder.pkl')
84
  logger.info("Models loaded successfully.")
85
  except FileNotFoundError as e:
86
- logger.error(f"Model files not found: {e}")
87
  raise HTTPException(status_code=500, detail="Trained model files not found.")
 
 
 
88
 
89
  def summarize_with_groq(text):
90
  try:
 
22
  logger.error("GROQ_API_KEY not found in environment variables.")
23
  raise Exception("GROQ_API_KEY not found in environment variables.")
24
 
25
+ # Log and clear proxy environment variables
26
  logger.info(f"HTTP_PROXY: {os.environ.get('HTTP_PROXY')}")
27
  logger.info(f"HTTPS_PROXY: {os.environ.get('HTTPS_PROXY')}")
28
  os.environ.pop("HTTP_PROXY", None)
 
40
 
41
  app = FastAPI()
42
 
43
+ # Enable CORS
44
  app.add_middleware(
45
  CORSMiddleware,
46
+ allow_origins=["*"],
47
  allow_credentials=True,
48
  allow_methods=["*"],
49
  allow_headers=["*"],
 
76
  teams = set(matches_df['home_team'].unique()).union(set(matches_df['away_team'].unique()))
77
  players = sorted([str(scorer) for scorer in goals_df['scorer'].dropna().unique() if pd.notna(scorer)])
78
 
79
+ # Load models with detailed logging
80
  try:
81
+ logger.info("Loading logistic_regression_model.pkl")
82
  logistic_model = joblib.load('model/logistic_regression_model.pkl')
83
+ logger.info("Loading linear_regression_team1_goals.pkl")
84
  linear_model_team1 = joblib.load('model/linear_regression_team1_goals.pkl')
85
+ logger.info("Loading linear_regression_team2_goals.pkl")
86
  linear_model_team2 = joblib.load('model/linear_regression_team2_goals.pkl')
87
+ logger.info("Loading label_encoder.pkl")
88
  le = joblib.load('model/label_encoder.pkl')
89
  logger.info("Models loaded successfully.")
90
  except FileNotFoundError as e:
91
+ logger.error(f"Model file not found: {e}")
92
  raise HTTPException(status_code=500, detail="Trained model files not found.")
93
+ except Exception as e:
94
+ logger.error(f"Error loading models: {str(e)}")
95
+ raise HTTPException(status_code=500, detail=f"Model loading failed: {str(e)}")
96
 
97
  def summarize_with_groq(text):
98
  try: