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( """ """, unsafe_allow_html=True, ) # Title and Description st.markdown('

🍷 Wine Quality Prediction

', unsafe_allow_html=True) st.write("Predict the quality of wine based on its chemical properties.") # Select Model st.markdown('

🔍 Select Prediction Model

', 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('

🍷 Enter Wine Properties

', 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'

Predicted Wine Quality: {int(prediction[0])}/10

', 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* 🚀")