File size: 3,939 Bytes
9642b8b e4fdc97 9642b8b e4fdc97 9642b8b e4fdc97 9642b8b e4fdc97 9642b8b e4fdc97 9642b8b e4fdc97 9642b8b e4fdc97 9642b8b e4fdc97 9642b8b e4fdc97 9642b8b e4fdc97 9642b8b e4fdc97 9642b8b e4fdc97 9642b8b e4fdc97 9642b8b e4fdc97 9642b8b e4fdc97 783bc55 |
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 |
import streamlit as st
import pickle
import numpy as np
import os
# Load all trained models
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",
}
# Streamlit UI Config
st.set_page_config(page_title="π· Wine Quality Predictor", layout="centered")
# Custom Styling for Background & UI
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,
)
# Title and Description
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.")
# Select Model
st.markdown('<h2 class="subtitle">π Select Prediction Model</h2>', unsafe_allow_html=True)
selected_model = st.selectbox("Choose a Model", list(MODEL_FILES.keys()))
# Load Selected Model
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.")
# User Inputs for Wine Features
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)
# Prepare input for model
input_data = np.array([[fixed_acidity, volatile_acidity, citric_acid, residual_sugar,
chlorides, free_sulfur_dioxide, total_sulfur_dioxide, density,
pH, sulphates, alcohol]])
# Prediction Button
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* π")
|