Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,31 +1,31 @@
|
|
1 |
-
from fastapi import FastAPI
|
2 |
-
import joblib
|
3 |
-
import uvicorn
|
4 |
-
|
5 |
-
app = FastAPI()
|
6 |
-
|
7 |
-
model = joblib.load('ridge_model.pkl')
|
8 |
-
poly = joblib.load('polynomial_transformer.pkl')
|
9 |
-
|
10 |
-
def predict_corrected_rank(percentile: float, total_candidates: int) -> float:
|
11 |
-
# Calculate initial predicted rank using the formula
|
12 |
-
predicted_rank = ((100 - percentile) * total_candidates) / 100
|
13 |
-
# Predict correction factor using the polynomial regression model
|
14 |
-
percentile_poly = poly.transform([[percentile]])
|
15 |
-
predicted_correction = model.predict(percentile_poly)[0][0]
|
16 |
-
# Adjust the predicted rank with the correction factor
|
17 |
-
corrected_rank = predicted_rank + predicted_correction
|
18 |
-
# Ensure the rank does not exceed the total number of candidates or become negative
|
19 |
-
corrected_rank = max(1, min(corrected_rank, total_candidates))
|
20 |
-
return corrected_rank
|
21 |
-
|
22 |
-
|
23 |
-
@app.get("/predict")
|
24 |
-
def get_corrected_rank(percentile: float, total_candidates: int):
|
25 |
-
corrected_rank = predict_corrected_rank(percentile, total_candidates)
|
26 |
-
return {"percentile": percentile, "total_candidates": total_candidates, "corrected_rank": corrected_rank}
|
27 |
-
|
28 |
-
|
29 |
-
if __name__ == "__main__":
|
30 |
-
# logger.info("Starting PreCollege Data Scraper Server...")
|
31 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
import joblib
|
3 |
+
import uvicorn
|
4 |
+
|
5 |
+
app = FastAPI()
|
6 |
+
|
7 |
+
model = joblib.load('ridge_model.pkl')
|
8 |
+
poly = joblib.load('polynomial_transformer.pkl')
|
9 |
+
|
10 |
+
def predict_corrected_rank(percentile: float, total_candidates: int) -> float:
|
11 |
+
# Calculate initial predicted rank using the formula
|
12 |
+
predicted_rank = ((100 - percentile) * total_candidates) / 100
|
13 |
+
# Predict correction factor using the polynomial regression model
|
14 |
+
percentile_poly = poly.transform([[percentile]])
|
15 |
+
predicted_correction = model.predict(percentile_poly)[0][0]
|
16 |
+
# Adjust the predicted rank with the correction factor
|
17 |
+
corrected_rank = predicted_rank + predicted_correction
|
18 |
+
# Ensure the rank does not exceed the total number of candidates or become negative
|
19 |
+
corrected_rank = max(1, min(corrected_rank, total_candidates))
|
20 |
+
return round(corrected_rank)
|
21 |
+
|
22 |
+
|
23 |
+
@app.get("/predict")
|
24 |
+
def get_corrected_rank(percentile: float, total_candidates: int):
|
25 |
+
corrected_rank = predict_corrected_rank(percentile, total_candidates)
|
26 |
+
return {"percentile": percentile, "total_candidates": total_candidates, "corrected_rank": corrected_rank}
|
27 |
+
|
28 |
+
|
29 |
+
if __name__ == "__main__":
|
30 |
+
# logger.info("Starting PreCollege Data Scraper Server...")
|
31 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|