|
import streamlit as st |
|
import pickle |
|
import numpy as np |
|
import os |
|
|
|
|
|
MODEL_FILES = { |
|
"KNN": "knn_model.pkl", |
|
"Random Forest": "random_forest_model.pkl", |
|
"Decision Tree": "decision_tree_model.pkl", |
|
"Bagging": "bagging_model.pkl", |
|
"Voting": "voting_model.pkl", |
|
} |
|
|
|
|
|
st.set_page_config(page_title="π· Wine Quality Predictor", layout="centered") |
|
|
|
|
|
st.markdown( |
|
""" |
|
<style> |
|
.stApp { |
|
background: linear-gradient(to right, #4B0101, #800020); |
|
color: white; |
|
} |
|
.title { |
|
font-size: 36px !important; |
|
font-weight: bold; |
|
color: #FFD700; /* Gold */ |
|
text-align: center; |
|
} |
|
.subtitle { |
|
font-size: 24px !important; |
|
font-weight: bold; |
|
color: #FFA500; /* Orange */ |
|
} |
|
.stSelectbox label, .stSlider label, .stNumberInput label { |
|
font-size: 18px !important; |
|
font-weight: bold; |
|
color: white; |
|
} |
|
.stButton>button { |
|
background-color: #FFD700; /* Gold */ |
|
color: #4B0101; /* Wine Red */ |
|
font-size: 18px; |
|
font-weight: bold; |
|
border-radius: 10px; |
|
} |
|
.stButton>button:hover { |
|
background-color: #FFA500; /* Orange */ |
|
color: white; |
|
} |
|
.prediction { |
|
font-size: 26px; |
|
font-weight: bold; |
|
color: #32CD32; /* Bright Green */ |
|
text-align: center; |
|
} |
|
</style> |
|
""", |
|
unsafe_allow_html=True, |
|
) |
|
|
|
|
|
st.markdown('<h1 class="title">π· Wine Quality Prediction</h1>', unsafe_allow_html=True) |
|
st.write("Predict the quality of wine based on its chemical properties.") |
|
|
|
|
|
st.markdown('<h2 class="subtitle">π Select Prediction Model</h2>', unsafe_allow_html=True) |
|
selected_model = st.selectbox("Choose a Model", list(MODEL_FILES.keys())) |
|
|
|
|
|
model_path = MODEL_FILES[selected_model] |
|
if os.path.exists(model_path): |
|
with open(model_path, "rb") as f: |
|
model = pickle.load(f) |
|
model_loaded = True |
|
else: |
|
model_loaded = False |
|
st.error(f"Model file '{model_path}' not found. Please upload the correct model file.") |
|
|
|
|
|
st.markdown('<h2 class="subtitle">π· Enter Wine Properties</h2>', unsafe_allow_html=True) |
|
fixed_acidity = st.number_input("Fixed Acidity", min_value=3.0, max_value=15.0, value=7.0) |
|
volatile_acidity = st.number_input("Volatile Acidity", min_value=0.0, max_value=2.0, value=0.5) |
|
citric_acid = st.number_input("Citric Acid", min_value=0.0, max_value=1.5, value=0.2) |
|
residual_sugar = st.number_input("Residual Sugar", min_value=0.1, max_value=15.0, value=2.0) |
|
chlorides = st.number_input("Chlorides", min_value=0.01, max_value=0.2, value=0.05) |
|
free_sulfur_dioxide = st.number_input("Free Sulfur Dioxide", min_value=1, max_value=100, value=30) |
|
total_sulfur_dioxide = st.number_input("Total Sulfur Dioxide", min_value=5, max_value=300, value=120) |
|
density = st.number_input("Density", min_value=0.98, max_value=1.1, value=0.995) |
|
pH = st.number_input("pH", min_value=2.5, max_value=4.5, value=3.2) |
|
sulphates = st.number_input("Sulphates", min_value=0.3, max_value=2.0, value=0.8) |
|
alcohol = st.number_input("Alcohol Content", min_value=5.0, max_value=20.0, value=10.0) |
|
|
|
|
|
input_data = np.array([[fixed_acidity, volatile_acidity, citric_acid, residual_sugar, |
|
chlorides, free_sulfur_dioxide, total_sulfur_dioxide, density, |
|
pH, sulphates, alcohol]]) |
|
|
|
|
|
if st.button("Predict Quality"): |
|
if model_loaded: |
|
prediction = model.predict(input_data) |
|
st.markdown(f'<p class="prediction">Predicted Wine Quality: {int(prediction[0])}/10</p>', unsafe_allow_html=True) |
|
else: |
|
st.error(f"Model file '{model_path}' not found. Please upload the correct model file.") |
|
|
|
st.write("*Powered by Machine Learning & AI* π") |
|
|