udbhav90 commited on
Commit
d035171
·
verified ·
1 Parent(s): db267fe

Upload folder using huggingface_hub

Browse files
Dockerfile ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.12-slim
2
+
3
+ # Set the working directory inside the container
4
+ WORKDIR /app
5
+
6
+ # Copy all files from the current directory to the container's working directory
7
+ COPY . .
8
+
9
+ # Install dependencies from the requirements file without using cache to reduce image size
10
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
11
+
12
+ EXPOSE 7860
13
+
14
+
15
+ # Define the command to start the application using Gunicorn with 4 worker processes
16
+ # - `-w 4`: Uses 4 worker processes for handling requests
17
+ # - `-b 0.0.0.0:7860`: Binds the server to port 7860 on all network interfaces
18
+ # - `app:app`: Runs the Flask app (assuming `app.py` contains the Flask instance named `app`)
19
+ CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:7860", "introvert_extrovert_predictor:app"]
introvert_extrovert_predictor.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import joblib
2
+ import pandas as pd
3
+ from flask import Flask, request, jsonify
4
+
5
+ # Initialize Flask app
6
+ app = Flask("Introvert Extrovert Predictor")
7
+
8
+ # Load the trained classification model
9
+ model = joblib.load("introvert_extrovert_predictor_v1_0.joblib")
10
+
11
+ # Home route
12
+ @app.get("/")
13
+ def home():
14
+ return "Welcome to the Introvert-Extrovert Prediction API!"
15
+
16
+ @app.post("/v1/personality/predict")
17
+ def predict_personality_single():
18
+ input_data = request.get_json()
19
+
20
+ # Prepare input sample
21
+ sample = {
22
+ "Time_spent_Alone": input_data["Time_spent_Alone"],
23
+ "Social_event_attendance": input_data["Social_event_attendance"],
24
+ "Going_outside": input_data["Going_outside"],
25
+ "Friends_circle_size": input_data["Friends_circle_size"],
26
+ "Post_frequency": input_data["Post_frequency"],
27
+ "Stage_fear": 1 if input_data["Stage_fear"].lower() == "yes" else 0,
28
+ "Drained_after_socializing": 1 if input_data["Drained_after_socializing"].lower() == "yes" else 0
29
+ }
30
+
31
+ # Convert to DataFrame and predict
32
+ input_df = pd.DataFrame([sample])
33
+ prediction = model.predict(input_df).tolist()[0]
34
+ personality = "Extrovert" if prediction == 1 else "Introvert"
35
+
36
+ return jsonify({'Predicted_Personality': personality})
37
+
38
+ @app.post("/v1/personality/predictbatch")
39
+ def predict_personality_batch():
40
+ # Get uploaded file
41
+ file = request.files['file']
42
+
43
+ # Read CSV file
44
+ input_df = pd.read_csv(file)
45
+
46
+ # Convert binary features to numerical (Yes → 1, No → 0)
47
+ input_df["Stage_fear"] = input_df["Stage_fear"].apply(lambda x: 1 if str(x).lower() == "yes" else 0)
48
+ input_df["Drained_after_socializing"] = input_df["Drained_after_socializing"].apply(lambda x: 1 if str(x).lower() == "yes" else 0)
49
+
50
+ # Predict personality
51
+ predictions = model.predict(input_df).tolist()
52
+ input_df["Predicted_Personality"] = ["Extrovert" if p == 1 else "Introvert" for p in predictions]
53
+
54
+ # Convert to dict for JSON output
55
+ result = input_df.to_dict(orient="records")
56
+ return jsonify(result)
57
+
58
+ # Run app
59
+ if __name__ == '__main__':
60
+ app.run(debug=True)
introvert_extrovert_predictor_v1_0.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cdbcb530cbf3579870897c40043dec4050c5231f226c8aa8dddae457c28b162c
3
+ size 10482322
requirements.txt ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ numpy==2.0.2
2
+ pandas==2.2.2
3
+ scikit-learn==1.6.1
4
+ matplotlib==3.10.0
5
+ seaborn==0.13.2
6
+ joblib==1.4.2
7
+ xgboost==2.1.4
8
+ requests==2.32.3
9
+ huggingface-hub==0.17.3
10
+ flask==2.2.2
11
+ gunicorn==20.1.0
12
+ uvicorn[standard]==0.23.2