Sirisha335 commited on
Commit
735f350
·
verified ·
1 Parent(s): 9931cf1

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. Dockerfile +1 -0
  2. Extraalearn.joblib +2 -2
  3. app.py +43 -24
  4. requirements.txt +4 -0
Dockerfile CHANGED
@@ -2,4 +2,5 @@ FROM python:3.9-slim
2
  WORKDIR /app
3
  COPY . .
4
  RUN pip install --no-cache-dir -r requirements.txt
 
5
  CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:7860", "app:app"]
 
2
  WORKDIR /app
3
  COPY . .
4
  RUN pip install --no-cache-dir -r requirements.txt
5
+ # Important: app:app refers to app.py and the Flask instance named 'app'
6
  CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:7860", "app:app"]
Extraalearn.joblib CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:24baf43ea0f346143f13d01b29bdfdb621b557660f1395a07cfc80ae2b7bc708
3
- size 143796
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ac845d7fb46e64e4860caffd4e491dba9a6c3bdd652d55e1d2c0ae7a4a4fed98
3
+ size 143810
app.py CHANGED
@@ -3,12 +3,13 @@ import joblib
3
  import pandas as pd
4
  from flask import Flask, request, jsonify
5
 
6
- # Initialize Flask app
7
  app = Flask(__name__)
8
 
9
  # Load the model
10
  model = joblib.load('Extraalearn.joblib')
11
 
 
12
  EXPECTED_FEATURES = [
13
  'age', 'website_visits', 'time_spent_on_website', 'page_views_per_visit',
14
  'current_occupation_Student', 'current_occupation_Unemployed',
@@ -21,33 +22,51 @@ EXPECTED_FEATURES = [
21
 
22
  @app.get('/')
23
  def home():
24
- return 'ExtraaLearn Lead Conversion API is Running'
25
 
26
  @app.post('/v1/predict')
27
- def predict():
28
  try:
29
  data = request.get_json()
30
- p = {}
31
- p['age'] = float(data.get('age', 0))
32
- p['website_visits'] = float(data.get('website_visits', 0))
33
- p['time_spent_on_website'] = float(data.get('time_spent_on_website', 0))
34
- p['page_views_per_visit'] = float(data.get('page_views_per_visit', 0))
35
- p['current_occupation_Student'] = 1 if data.get('current_occupation') == 'Student' else 0
36
- p['current_occupation_Unemployed'] = 1 if data.get('current_occupation') == 'Unemployed' else 0
37
- p['first_interaction_Website'] = 1 if data.get('first_interaction') == 'Website' else 0
38
- p['profile_completed_Low'] = 1 if data.get('profile_completed') == 'Low' else 0
39
- p['profile_completed_Medium'] = 1 if data.get('profile_completed') == 'Medium' else 0
40
- p['last_activity_Phone Activity'] = 1 if data.get('last_activity') == 'Phone Activity' else 0
41
- p['last_activity_Website Activity'] = 1 if data.get('last_activity') == 'Website Activity' else 0
42
- p['print_media_type1_Yes'] = 1 if data.get('print_media_type1') == 'Yes' else 0
43
- p['print_media_type2_Yes'] = 1 if data.get('print_media_type2') == 'Yes' else 0
44
- p['digital_media_Yes'] = 1 if data.get('digital_media') == 'Yes' else 0
45
- p['educational_channels_Yes'] = 1 if data.get('educational_channels') == 'Yes' else 0
46
- p['referral_Yes'] = 1 if data.get('referral') == 'Yes' else 0
47
-
48
- df_final = pd.DataFrame([p])[EXPECTED_FEATURES]
49
- prediction_proba = model.predict_proba(df_final)[:, 1].tolist()[0]
50
- return jsonify({'Conversion_Probability': float(prediction_proba)})
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  except Exception as e:
52
  return jsonify({'error': str(e)}), 400
53
 
 
3
  import pandas as pd
4
  from flask import Flask, request, jsonify
5
 
6
+ # Create the Flask app
7
  app = Flask(__name__)
8
 
9
  # Load the model
10
  model = joblib.load('Extraalearn.joblib')
11
 
12
+ # Define the expected feature columns from training (excluding 'status')
13
  EXPECTED_FEATURES = [
14
  'age', 'website_visits', 'time_spent_on_website', 'page_views_per_visit',
15
  'current_occupation_Student', 'current_occupation_Unemployed',
 
22
 
23
  @app.get('/')
24
  def home():
25
+ return 'ExtraaLearn API is Running'
26
 
27
  @app.post('/v1/predict')
28
+ def predict_conversion_probability(): # Renamed endpoint for clarity
29
  try:
30
  data = request.get_json()
31
+
32
+ # Create a dictionary to hold the processed features
33
+ processed_data = {}
34
+
35
+ # 1. Map Numerical Features
36
+ processed_data['age'] = float(data.get('age', 0))
37
+ processed_data['website_visits'] = float(data.get('website_visits', 0))
38
+ processed_data['time_spent_on_website'] = float(data.get('time_spent_on_website', 0))
39
+ processed_data['page_views_per_visit'] = float(data.get('page_views_per_visit', 0))
40
+
41
+ # 2. Map Categorical Features (One-Hot Encoding logic)
42
+ # Note: 'Professional', 'Mobile App', 'High', 'Email Activity', and 'No' are the baselines (drop_first)
43
+
44
+ occ = data.get('current_occupation', '')
45
+ processed_data['current_occupation_Student'] = 1 if occ == 'Student' else 0
46
+ processed_data['current_occupation_Unemployed'] = 1 if occ == 'Unemployed' else 0
47
+
48
+ processed_data['first_interaction_Website'] = 1 if data.get('first_interaction', '') == 'Website' else 0
49
+
50
+ prof = data.get('profile_completed', '')
51
+ processed_data['profile_completed_Low'] = 1 if prof == 'Low' else 0
52
+ processed_data['profile_completed_Medium'] = 1 if prof == 'Medium' else 0
53
+
54
+ last = data.get('last_activity', '')
55
+ processed_data['last_activity_Phone Activity'] = 1 if last == 'Phone Activity' else 0
56
+ processed_data['last_activity_Website Activity'] = 1 if last == 'Website Activity' else 0
57
+
58
+ processed_data['print_media_type1_Yes'] = 1 if data.get('print_media_type1', '') == 'Yes' else 0
59
+ processed_data['print_media_type2_Yes'] = 1 if data.get('print_media_type2', '') == 'Yes' else 0
60
+ processed_data['digital_media_Yes'] = 1 if data.get('digital_media', '') == 'Yes' else 0
61
+ processed_data['educational_channels_Yes'] = 1 if data.get('educational_channels', '') == 'Yes' else 0
62
+ processed_data['referral_Yes'] = 1 if data.get('referral', '') == 'Yes' else 0
63
+
64
+ # Convert dictionary to DataFrame with the exact training order
65
+ df_final = pd.DataFrame([processed_data])[EXPECTED_FEATURES]
66
+
67
+ # Predict probability of conversion (positive class is 1)
68
+ prediction_proba = model.predict_proba(df_final)[:, 1].tolist()[0] # Use predict_proba
69
+ return jsonify({'Conversion_Probability': float(prediction_proba)}) # Changed key to Conversion_Probability
70
  except Exception as e:
71
  return jsonify({'error': str(e)}), 400
72
 
requirements.txt CHANGED
@@ -4,6 +4,10 @@ scikit-learn==1.6.1
4
  seaborn==0.13.2
5
  joblib==1.4.2
6
  xgboost==2.1.4
 
 
7
  flask==2.2.2
8
  gunicorn==20.1.0
9
  requests==2.32.3
 
 
 
4
  seaborn==0.13.2
5
  joblib==1.4.2
6
  xgboost==2.1.4
7
+ joblib==1.4.2
8
+ Werkzeug==2.2.2
9
  flask==2.2.2
10
  gunicorn==20.1.0
11
  requests==2.32.3
12
+ uvicorn[standard]
13
+ streamlit==1.43.2