ak0601 commited on
Commit
4892e5e
·
verified ·
1 Parent(s): 63069e4

Upload 5 files

Browse files
Files changed (5) hide show
  1. Dockerfile +13 -0
  2. app.py +31 -0
  3. polynomial_transformer.pkl +3 -0
  4. requirements.txt +19 -0
  5. ridge_model.pkl +3 -0
Dockerfile ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+
3
+ RUN useradd -m -u 1000 user
4
+ USER user
5
+ ENV PATH="/home/user/.local/bin:$PATH"
6
+
7
+ WORKDIR /app
8
+
9
+ COPY --chown=user ./requirements.txt requirements.txt
10
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
11
+
12
+ COPY --chown=user . /app
13
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py ADDED
@@ -0,0 +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)
polynomial_transformer.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1e0238c7645aff3bb63d4dccb5ba4149c9654dd7485ee5e2bd7f60a5e98b0ffc
3
+ size 255
requirements.txt ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ annotated-types==0.7.0
2
+ anyio==4.6.2.post1
3
+ click==8.1.7
4
+ colorama==0.4.6
5
+ exceptiongroup==1.2.2
6
+ fastapi==0.115.5
7
+ h11==0.14.0
8
+ idna==3.10
9
+ joblib==1.4.2
10
+ numpy==2.0.2
11
+ pydantic==2.9.2
12
+ pydantic_core==2.23.4
13
+ scikit-learn==1.5.2
14
+ scipy==1.13.1
15
+ sniffio==1.3.1
16
+ starlette==0.41.2
17
+ threadpoolctl==3.5.0
18
+ typing_extensions==4.12.2
19
+ uvicorn==0.32.0
ridge_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8bac71376f4257c5b3e3394609f265b1f575323066bf815f3e8a680f50606a34
3
+ size 607