Update app.py
Browse files
app.py
CHANGED
|
@@ -1,2 +1,76 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pickle
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import numpy as np
|
| 5 |
+
import os
|
| 6 |
+
from sklearn.preprocessing import StandardScaler
|
| 7 |
+
|
| 8 |
+
# Load the trained pipeline model
|
| 9 |
+
MODEL_FILES = {
|
| 10 |
+
"Random Forest": "random_forest_pipeline.pkl", # Ensure correct paths
|
| 11 |
+
"Decision Tree": "decision_tree_pipeline.pkl",
|
| 12 |
+
"KNN": "knn_pipeline.pkl",
|
| 13 |
+
"Bagging": "bagging_pipeline.pkl",
|
| 14 |
+
"Voting": "voting_pipeline.pkl",
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
# Streamlit UI Setup
|
| 18 |
+
st.set_page_config(page_title="Wine Quality Prediction 🍷🔬", layout="centered")
|
| 19 |
+
|
| 20 |
+
# Custom Styling
|
| 21 |
+
st.markdown(
|
| 22 |
+
"""
|
| 23 |
+
<style>
|
| 24 |
+
.stApp { background-color: #003366; color: white; }
|
| 25 |
+
.title { font-size: 36px !important; font-weight: bold; color: white; text-align: center; }
|
| 26 |
+
.subtitle { font-size: 24px !important; font-weight: bold; color: #ffcc00; }
|
| 27 |
+
.stSelectbox label, .stNumberInput label, .stSlider label { font-size: 18px; font-weight: bold; color: white; }
|
| 28 |
+
.stButton>button { background-color: #ffcc00; color: #003366; font-size: 18px; font-weight: bold; border-radius: 10px; }
|
| 29 |
+
.stButton>button:hover { background-color: #ff9900; color: white; }
|
| 30 |
+
.prediction { font-size: 26px; font-weight: bold; color: #32CD32; text-align: center; }
|
| 31 |
+
</style>
|
| 32 |
+
""",
|
| 33 |
+
unsafe_allow_html=True,
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
st.markdown('<h1 class="title">Wine Quality Prediction 🍷🔬</h1>', unsafe_allow_html=True)
|
| 37 |
+
st.write("Predicting Wine Quality based on wine parameters.")
|
| 38 |
+
|
| 39 |
+
# Model Selection
|
| 40 |
+
st.markdown('<h2 class="subtitle">Select Prediction Model 🔍</h2>', unsafe_allow_html=True)
|
| 41 |
+
selected_model = st.selectbox("Select Prediction Model", list(MODEL_FILES.keys()))
|
| 42 |
+
|
| 43 |
+
# Load Model
|
| 44 |
+
model_path = MODEL_FILES[selected_model]
|
| 45 |
+
if os.path.exists(model_path):
|
| 46 |
+
with open(model_path, "rb") as f:
|
| 47 |
+
model = pickle.load(f)
|
| 48 |
+
model_loaded = True
|
| 49 |
+
else:
|
| 50 |
+
model_loaded = False
|
| 51 |
+
st.error(f"Model file '{model_path}' not found. Please check your uploaded files.")
|
| 52 |
+
|
| 53 |
+
# User Inputs
|
| 54 |
+
fixed_acidity = st.number_input("Fixed Acidity", min_value=4.6, max_value=15.9, value=7.6)
|
| 55 |
+
volatile_acidity = st.number_input("Volatile Acidity", min_value=0.12, max_value=1.58, value=1.2)
|
| 56 |
+
citric_acid = st.number_input("Citric Acid", min_value=0.0, max_value=1.66, value=0.5)
|
| 57 |
+
residual_sugar = st.number_input("Residual Sugar", min_value=0.9, max_value=15.5, value=5.8)
|
| 58 |
+
chlorides = st.number_input("Chlorides", min_value=0.012, max_value=0.611, value=0.044)
|
| 59 |
+
free_sulfur_dioxide = st.slider("Free Sulfur Dioxide", 1, 72, 15)
|
| 60 |
+
total_sulfur_dioxide = st.slider("Total Sulfur Dioxide", 6, 289, 100)
|
| 61 |
+
density = st.number_input("Density", min_value=0.99007, max_value=1.00369, value=1.00111)
|
| 62 |
+
pH = st.number_input("pH", min_value=2.74, max_value=4.01, value=3.12)
|
| 63 |
+
sulphates = st.number_input("Sulphates", min_value=0.33, max_value=2.00, value=0.9)
|
| 64 |
+
alcohol = st.number_input("Alcohol", min_value=8.4, max_value=14.9, value=10.2)
|
| 65 |
+
|
| 66 |
+
# Prepare input for prediction
|
| 67 |
+
input_data = np.array([[fixed_acidity, volatile_acidity, citric_acid, residual_sugar, chlorides,
|
| 68 |
+
free_sulfur_dioxide, total_sulfur_dioxide, density, pH, sulphates, alcohol]])
|
| 69 |
+
|
| 70 |
+
# Prediction
|
| 71 |
+
if st.button("Predict Wine Quality"):
|
| 72 |
+
if model_loaded:
|
| 73 |
+
prediction = model.predict(input_data)
|
| 74 |
+
st.markdown(f'<p class="prediction">Predicted Wine Quality: {prediction[0]}</p>', unsafe_allow_html=True)
|
| 75 |
+
else:
|
| 76 |
+
st.error(f"Model file '{model_path}' not found. Please upload the model file and try again.")
|