Spaces:
Build error
Build error
Upload 5 files
Browse files- app1.py +141 -0
- encoder.pkl +3 -0
- ensemble_clf.pkl +3 -0
- label_encoder.pkl +3 -0
- requirements.txt +5 -0
app1.py
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import joblib
|
| 4 |
+
|
| 5 |
+
# Load the saved models and encoders
|
| 6 |
+
ensemble_clf = joblib.load('ensemble_clf.pkl')
|
| 7 |
+
encoder = joblib.load('encoder.pkl')
|
| 8 |
+
label_encoder = joblib.load('label_encoder.pkl')
|
| 9 |
+
|
| 10 |
+
# Define custom CSS for light and dark modes
|
| 11 |
+
def set_page_styles(dark_mode):
|
| 12 |
+
if dark_mode:
|
| 13 |
+
st.markdown(
|
| 14 |
+
"""<style>
|
| 15 |
+
body {
|
| 16 |
+
background-color: #ffffff;
|
| 17 |
+
color: #ffffff;
|
| 18 |
+
}
|
| 19 |
+
.stButton > button {
|
| 20 |
+
background-color: #333333;
|
| 21 |
+
color: #ffffff;
|
| 22 |
+
border: 1px solid #444444;
|
| 23 |
+
}
|
| 24 |
+
.stTextInput > div > input, .stSelectbox > div > div > div {
|
| 25 |
+
background-color: #333333;
|
| 26 |
+
color: #ffffff;
|
| 27 |
+
border: 1px solid #444444;
|
| 28 |
+
}
|
| 29 |
+
.stSidebar {
|
| 30 |
+
background-color: #1e1e1e;
|
| 31 |
+
color: #ffffff;
|
| 32 |
+
}
|
| 33 |
+
.css-1aumxhk {
|
| 34 |
+
background-color: #1e1e1e;
|
| 35 |
+
color: #ffffff;
|
| 36 |
+
}
|
| 37 |
+
</style>""",
|
| 38 |
+
unsafe_allow_html=True,
|
| 39 |
+
)
|
| 40 |
+
else:
|
| 41 |
+
st.markdown(
|
| 42 |
+
"""<style>
|
| 43 |
+
body {
|
| 44 |
+
background-color: #ffffff;
|
| 45 |
+
color: #000000;
|
| 46 |
+
}
|
| 47 |
+
.stButton > button {
|
| 48 |
+
background-color: #f0f0f0;
|
| 49 |
+
color: #000000;
|
| 50 |
+
border: 1px solid #cccccc;
|
| 51 |
+
}
|
| 52 |
+
.stTextInput > div > input, .stSelectbox > div > div > div {
|
| 53 |
+
background-color: #ffffff;
|
| 54 |
+
color: #000000;
|
| 55 |
+
border: 1px solid #cccccc;
|
| 56 |
+
}
|
| 57 |
+
.stSidebar {
|
| 58 |
+
background-color: #f8f9fa;
|
| 59 |
+
color: #000000;
|
| 60 |
+
}
|
| 61 |
+
.css-1aumxhk {
|
| 62 |
+
background-color: #f8f9fa;
|
| 63 |
+
color: #000000;
|
| 64 |
+
}
|
| 65 |
+
</style>""",
|
| 66 |
+
unsafe_allow_html=True,
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
# Page configuration
|
| 70 |
+
st.set_page_config(page_title="Laptop Recommendation System", layout="centered")
|
| 71 |
+
|
| 72 |
+
# Sidebar for theme toggle
|
| 73 |
+
dark_mode = st.sidebar.checkbox("Dark Mode")
|
| 74 |
+
set_page_styles(dark_mode)
|
| 75 |
+
|
| 76 |
+
# Streamlit app title
|
| 77 |
+
st.title("Laptop Recommendation System")
|
| 78 |
+
|
| 79 |
+
# Input fields for user preferences
|
| 80 |
+
st.header("Enter Your Preferences")
|
| 81 |
+
with st.form("user_preferences_form"):
|
| 82 |
+
persona = st.selectbox(
|
| 83 |
+
"Select Persona", ["Student", "Gamer", "Professional", "Creative", "Engineering", "Business"]
|
| 84 |
+
)
|
| 85 |
+
usage = st.text_input(
|
| 86 |
+
"Describe Usage (e.g., Studying, Gaming, Video Editing)", "Studying, assignments, research"
|
| 87 |
+
)
|
| 88 |
+
processor = st.selectbox(
|
| 89 |
+
"Preferred Processor", ["Intel Core i5 / AMD Ryzen 5", "Intel Core i7 / AMD Ryzen 7"]
|
| 90 |
+
)
|
| 91 |
+
ram = st.selectbox("Preferred RAM", ["8GB DDR4", "16GB DDR4"])
|
| 92 |
+
graphics = st.selectbox(
|
| 93 |
+
"Preferred Graphics", [
|
| 94 |
+
"Integrated (Intel Iris Xe)",
|
| 95 |
+
"NVIDIA RTX 3060 / AMD Radeon RX 6600XT",
|
| 96 |
+
"NVIDIA RTX 3070 / AMD Radeon RX 6700M",
|
| 97 |
+
"NVIDIA RTX 3080 / AMD Radeon RX 6800M",
|
| 98 |
+
"NVIDIA RTX 3090 / AMD Radeon RX 6900M",
|
| 99 |
+
"Integrated (Intel UHD / AMD Vega)",
|
| 100 |
+
"Integrated (Intel Iris Xe) or NVIDIA MX550",
|
| 101 |
+
]
|
| 102 |
+
)
|
| 103 |
+
storage = st.selectbox(
|
| 104 |
+
"Preferred Storage", [
|
| 105 |
+
"256GB SSD",
|
| 106 |
+
"512GB SSD",
|
| 107 |
+
"1TB HDD",
|
| 108 |
+
"512GB SSD + 1TB HDD",
|
| 109 |
+
"1TB SSD + 1TB HDD",
|
| 110 |
+
"1TB SSD + 2TB HDD",
|
| 111 |
+
]
|
| 112 |
+
)
|
| 113 |
+
display = st.selectbox("Preferred Display", ["13-15\" Full HD", "15-17\" QHD/4K"])
|
| 114 |
+
battery = st.selectbox(
|
| 115 |
+
"Battery Life Expectation", ["6-8 hours", "7-9 hours", "8-12 hours", "12+ hours"]
|
| 116 |
+
)
|
| 117 |
+
submit_button = st.form_submit_button(label="Get Recommendation")
|
| 118 |
+
|
| 119 |
+
# If form is submitted
|
| 120 |
+
if submit_button:
|
| 121 |
+
# Create a DataFrame from user inputs
|
| 122 |
+
new_user = pd.DataFrame({
|
| 123 |
+
'Persona': [persona],
|
| 124 |
+
'Usage': [usage],
|
| 125 |
+
'Processor': [processor],
|
| 126 |
+
'RAM': [ram],
|
| 127 |
+
'Graphics': [graphics],
|
| 128 |
+
'Storage': [storage],
|
| 129 |
+
'Display': [display],
|
| 130 |
+
'Battery Life': [battery]
|
| 131 |
+
})
|
| 132 |
+
|
| 133 |
+
# Encode the user input
|
| 134 |
+
new_user_encoded = encoder.transform(new_user)
|
| 135 |
+
|
| 136 |
+
# Predict the laptop specification label
|
| 137 |
+
predicted_label = label_encoder.inverse_transform(ensemble_clf.predict(new_user_encoded))
|
| 138 |
+
|
| 139 |
+
# Display the prediction
|
| 140 |
+
st.subheader("Recommended Laptop Specification")
|
| 141 |
+
st.success(f"**{predicted_label[0]}**")
|
encoder.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:87d7246e07a7fdcc61233b1b6d4ccf9f1c605b118e7d1d9111b806ac75ecb6c1
|
| 3 |
+
size 4299
|
ensemble_clf.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:806acaa9cd16f648e510d8d606af500adc9daf6296c3fc1ec0f775b743074648
|
| 3 |
+
size 415937
|
label_encoder.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:33074751a1ba25e5b54e3558448cc37188fde2e65c370bf6c095576f8fde0d98
|
| 3 |
+
size 1106
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Flask
|
| 2 |
+
pandas
|
| 3 |
+
joblib
|
| 4 |
+
scikit-learn
|
| 5 |
+
# Add any additional dependencies here
|