KunalThakare279 commited on
Commit
07d207a
·
verified ·
1 Parent(s): 19cbb28

Upload 4 files

Browse files
Files changed (4) hide show
  1. Dockerfile +36 -0
  2. app.py +34 -0
  3. model.py +39 -0
  4. requirements.txt +6 -0
Dockerfile ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ARG PYTHON_VERSION=3.10
2
+ FROM python:${PYTHON_VERSION}-slim as base
3
+
4
+ # Prevents Python from writing pyc files.
5
+ ENV PYTHONDONTWRITEBYTECODE=1
6
+
7
+ ENV PYTHONUNBUFFERED=1
8
+
9
+ WORKDIR /app
10
+
11
+ ARG UID=10001
12
+ RUN adduser \
13
+ --disabled-password \
14
+ --gecos "" \
15
+ --home "/nonexistent" \
16
+ --shell "/sbin/nologin" \
17
+ --no-create-home \
18
+ --uid "${UID}" \
19
+ appuser
20
+
21
+ RUN --mount=type=cache,target=/root/.cache/pip \
22
+ --mount=type=bind,source=requirements.txt,target=requirements.txt \
23
+ python -m pip install -r requirements.txt
24
+
25
+ # Switch to the non-privileged user to run the application.
26
+ USER appuser
27
+
28
+ # Copy the source code into the container.
29
+ COPY . .
30
+ COPY . .env
31
+
32
+ # Expose the port that the application listens on.
33
+ EXPOSE 8000
34
+
35
+ # Run the application.
36
+ CMD ["gunicorn", "app:app", "-b", "0.0.0.0:8000"]
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, request, jsonify
2
+ from model import get_colleges, get_courses_for_zone # Import the model function
3
+
4
+ import pandas as pd
5
+ import pickle
6
+
7
+ app = Flask(__name__)
8
+
9
+ zones = ['Amravati', 'Pune', 'Aurangabad', 'Mumbai & Thane', 'Konkan',
10
+ 'Nagpur', 'Nashik']
11
+
12
+ @app.route('/', methods=['GET', 'POST'])
13
+ def index():
14
+ colleges = []
15
+ if request.method == 'POST':
16
+ # Get data from the form
17
+ marks = float(request.form['marks'])
18
+ zone = request.form['zone']
19
+ course = request.form['course']
20
+
21
+ # Call the get_colleges function to predict the list of colleges
22
+ colleges = get_colleges(marks, zone, course)
23
+
24
+ return render_template('index.html', colleges=colleges, zones = zones)
25
+
26
+ @app.route('/get_courses', methods=['POST'])
27
+ def get_courses():
28
+ zone = request.json['zone']
29
+ courses = get_courses_for_zone(zone)
30
+ courses = courses.tolist()
31
+ return jsonify(courses)
32
+
33
+ if __name__ == '__main__':
34
+ app.run(debug=True)
model.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import pickle
3
+ import warnings
4
+ warnings.filterwarnings("ignore")
5
+
6
+ with open("static/rf_pipeline.pkl", "rb") as f:
7
+ pipeline2 = pickle.load(f)
8
+
9
+ data = pd.read_csv("static/zone_course_and_colleges.csv")
10
+
11
+ def get_prediction(college_name, course_name = "Computer Science and Engineering"):
12
+ template = pd.DataFrame([[college_name,
13
+ course_name,
14
+ "OPEN",
15
+ "General",
16
+ "State",
17
+ 2024,
18
+ 1]],
19
+ columns=['college_name', 'course_name', 'category', 'gender', 'seat_level_attribute', 'year', 'round'])
20
+ return pipeline2.predict(template)
21
+
22
+ def get_colleges(marks, zone, course):
23
+ # data = pd.read_csv("static/zone_course_and_colleges.csv")
24
+ # print(data[(data["zone"] == zone) & (data["course_name"] == course)]["colleges"].values[0])
25
+ try:
26
+ colleges = list(eval(data[(data["zone"] == zone.strip()) & (data["course_name"] == course.strip())]["colleges"].values[0]))
27
+ except:
28
+ return ["Too less to get into"]
29
+ college_data = []
30
+ for college in colleges:
31
+ prediciton = get_prediction(college, course)
32
+ if prediciton <= marks:
33
+ college_data.append(college)
34
+ return college_data
35
+
36
+ def get_courses_for_zone(zone):
37
+ row = data[data["zone"] == zone.strip()]
38
+ courses = row["course_name"].unique()
39
+ return courses
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ flask
2
+ requests
3
+ pandas
4
+ gunicorn
5
+ python-dotenv
6
+ scikit-learn