Dewasheesh commited on
Commit
f2063fe
·
verified ·
1 Parent(s): 7d2e0c6

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +15 -12
  2. app.py +126 -0
  3. requirements.txt +7 -3
Dockerfile CHANGED
@@ -1,20 +1,23 @@
1
- FROM python:3.13.5-slim
 
2
 
 
3
  WORKDIR /app
4
 
5
- RUN apt-get update && apt-get install -y \
6
- build-essential \
7
- curl \
8
- git \
9
- && rm -rf /var/lib/apt/lists/*
10
-
11
- COPY requirements.txt ./
12
- COPY src/ ./src/
13
 
 
14
  RUN pip3 install -r requirements.txt
15
 
16
- EXPOSE 8501
 
 
 
 
 
17
 
18
- HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
19
 
20
- ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
 
 
1
+ # Use a minimal base image with Python 3.9 installed
2
+ FROM python:3.9
3
 
4
+ # Set the working directory inside the container to /app
5
  WORKDIR /app
6
 
7
+ # Copy all files from the current directory on the host to the container's /app directory
8
+ COPY . .
 
 
 
 
 
 
9
 
10
+ # Install Python dependencies listed in requirements.txt
11
  RUN pip3 install -r requirements.txt
12
 
13
+ RUN useradd -m -u 1000 user
14
+ USER user
15
+ ENV HOME=/home/user \
16
+ PATH=/home/user/.local/bin:$PATH
17
+
18
+ WORKDIR $HOME/app
19
 
20
+ COPY --chown=user . $HOME/app
21
 
22
+ # Define the command to run the Streamlit app on port "8501" and make it accessible externally
23
+ CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
app.py ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # tourism_project/deployment/app.py
2
+ import streamlit as st
3
+ import pandas as pd
4
+ from huggingface_hub import hf_hub_download
5
+ import joblib
6
+ import os
7
+
8
+ st.set_page_config(page_title="Visa With Us - Prediction App", layout="centered")
9
+
10
+ # --------------------------
11
+ # CONFIG
12
+ # --------------------------
13
+ MODEL_REPO = "Dewasheesh/test-mlops"
14
+ MODEL_FILENAME = "best_test-mlops_v1.joblib"
15
+
16
+ @st.cache_resource
17
+ def load_model(repo_id: str, filename: str):
18
+ """Download and load joblib model from Hugging Face Hub (cached)."""
19
+ try:
20
+ #st.info("Loading model...")
21
+ model_path = hf_hub_download(repo_id=repo_id, filename=filename)
22
+ model = joblib.load(model_path)
23
+ return model
24
+ except Exception as e:
25
+ st.error(f"Failed to load model: {e}")
26
+ return None
27
+
28
+ model = load_model(MODEL_REPO, MODEL_FILENAME)
29
+
30
+ st.title("Visa With Us - Prediction App")
31
+ st.write(
32
+ "This app predicts whether a customer will purchase the Wellness Tourism Package."
33
+ )
34
+
35
+ st.markdown("---")
36
+ st.header("Features")
37
+
38
+ # Numeric Inputs
39
+ Age = st.number_input("Age", min_value=0, max_value=120, value=35)
40
+ CityTier = st.selectbox("City Tier", [1, 2, 3], index=1)
41
+ DurationOfPitch = st.number_input("Duration Of Pitch (minutes)", 0, 600, 10)
42
+ NumberOfPersonVisiting = st.number_input("Number Of Persons Visiting", 1, 20, 2)
43
+ NumberOfFollowups = st.number_input("Number Of Followups", 0, 50, 1)
44
+ PreferredPropertyStar = st.number_input("Preferred Property Star", 1, 7, 4)
45
+ NumberOfTrips = st.number_input("Number Of Trips (past)", 0, 50, 2)
46
+ Passport = st.selectbox("Passport", [1, 0], index=1)
47
+ PitchSatisfactionScore = st.slider("Pitch Satisfaction Score", 0, 10, 7)
48
+ OwnCar = st.selectbox("Own Car", [1, 0], index=1)
49
+ NumberOfChildrenVisiting = st.number_input("Number Of Children Visiting", 0, 10, 0)
50
+ MonthlyIncome = st.number_input("Monthly Income", 0, 10_000_000, 50000, step=1000)
51
+
52
+
53
+ # --------------------------
54
+ # CATEGORICAL VALUES
55
+ # --------------------------
56
+ TYPEOFCONTACT = ["Self Enquiry", "Company Invited"]
57
+
58
+ OCCUPATION = ["Salaried", "Small Business", "Large Business", "Free Lancer"]
59
+
60
+ GENDER = ["Male", "Female"]
61
+
62
+ PRODUCTPITCHED = ["Basic", "Deluxe", "Standard", "Super Deluxe", "King"]
63
+
64
+ MARITALSTATUS = ["Married", "Divorced", "Unmarried"]
65
+
66
+ DESIGNATION = ["Executive", "Manager", "Senior Manager", "AVP", "VP"]
67
+
68
+ # Selectboxes for categories
69
+ TypeofContact = st.selectbox("Type of Contact", TYPEOFCONTACT)
70
+ Occupation = st.selectbox("Occupation", OCCUPATION)
71
+ Gender = st.selectbox("Gender", GENDER)
72
+ ProductPitched = st.selectbox("Product Pitched", PRODUCTPITCHED)
73
+ MaritalStatus = st.selectbox("Marital Status", MARITALSTATUS)
74
+ Designation = st.selectbox("Designation", DESIGNATION)
75
+
76
+ # Assemble input
77
+ input_data = pd.DataFrame([{
78
+ "Age": Age,
79
+ "CityTier": CityTier,
80
+ "DurationOfPitch": DurationOfPitch,
81
+ "NumberOfPersonVisiting": NumberOfPersonVisiting,
82
+ "NumberOfFollowups": NumberOfFollowups,
83
+ "PreferredPropertyStar": PreferredPropertyStar,
84
+ "NumberOfTrips": NumberOfTrips,
85
+ "Passport": Passport,
86
+ "PitchSatisfactionScore": PitchSatisfactionScore,
87
+ "OwnCar": OwnCar,
88
+ "NumberOfChildrenVisiting": NumberOfChildrenVisiting,
89
+ "MonthlyIncome": MonthlyIncome,
90
+
91
+ "TypeofContact": TypeofContact,
92
+ "Occupation": Occupation,
93
+ "Gender": Gender,
94
+ "ProductPitched": ProductPitched,
95
+ "MaritalStatus": MaritalStatus,
96
+ "Designation": Designation,
97
+ }])
98
+
99
+ st.markdown("### Preview Input")
100
+ st.dataframe(input_data)
101
+
102
+ # --------------------------
103
+ # PREDICT
104
+ # --------------------------
105
+ if st.button("Predict"):
106
+ if model is None:
107
+ st.error("Model not loaded.")
108
+ else:
109
+ try:
110
+ pred = model.predict(input_data)[0]
111
+
112
+ # probability
113
+ proba_text = ""
114
+ if hasattr(model, "predict_proba"):
115
+ proba = model.predict_proba(input_data)
116
+ if proba.shape[1] == 2:
117
+ proba_text = f" (Probability: {proba[0,1]:.3f})"
118
+
119
+ result = "Purchase" if int(pred) == 1 else "No Purchase"
120
+ st.success(f"Prediction: **{result}**{proba_text}")
121
+
122
+ except Exception as e:
123
+ st.error(f"Prediction failed: {e}")
124
+
125
+ st.markdown("---")
126
+ st.caption("All categorical fields are restricted to valid training values to prevent model mismatch.")
requirements.txt CHANGED
@@ -1,3 +1,7 @@
1
- altair
2
- pandas
3
- streamlit
 
 
 
 
 
1
+ pandas==2.2.2
2
+ huggingface_hub==0.32.6
3
+ streamlit==1.43.2
4
+ joblib==1.5.1
5
+ scikit-learn==1.6.0
6
+ xgboost==2.1.4
7
+ mlflow==3.0.1