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