Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import numpy as np | |
| import pickle | |
| # Function to load the trained model # Cache the model so it's loaded only once per session | |
| def load_model(model_file): | |
| with open(model_file, 'rb') as f: | |
| model = pickle.load(f) | |
| return model | |
| # Function to predict wine quality | |
| def predict_quality(model, features): | |
| input_features = np.array(features).reshape(1, -1) | |
| prediction = model.predict(input_features) | |
| predicted_quality = prediction[0] | |
| return predicted_quality | |
| # Load the model | |
| model_file = 'model.pkl' # Replace with your model file path | |
| model = load_model(model_file) | |
| # Streamlit UI | |
| st.title('Wine Quality Prediction') | |
| # Input fields for each feature | |
| st.header('Input Features') | |
| fixed_acidity = st.slider('Fixed Acidity', min_value=4.0, max_value=16.0, value=8.0, step=0.1) | |
| volatile_acidity = st.slider('Volatile Acidity', min_value=0.1, max_value=2.0, value=0.5, step=0.01) | |
| citric_acid = st.slider('Citric Acid', min_value=0.0, max_value=1.0, value=0.5, step=0.01) | |
| residual_sugar = st.slider('Residual Sugar', min_value=0.0, max_value=20.0, value=10.0, step=0.1) | |
| chlorides = st.slider('Chlorides', min_value=0.0, max_value=1.0, value=0.08, step=0.01) | |
| free_sulfur_dioxide = st.slider('Free Sulfur Dioxide', min_value=1, max_value=100, value=30, step=1) | |
| total_sulfur_dioxide = st.slider('Total Sulfur Dioxide', min_value=1, max_value=300, value=100, step=1) | |
| density = st.slider('Density', min_value=0.8, max_value=1.0, value=0.996, step=0.001) | |
| pH = st.slider('pH', min_value=2.0, max_value=4.0, value=3.0, step=0.01) | |
| sulphates = st.slider('Sulphates', min_value=0.2, max_value=2.0, value=0.5, step=0.01) | |
| alcohol = st.slider('Alcohol', min_value=8.0, max_value=15.0, value=10.0, step=0.1) | |
| # Predict button | |
| if st.button('Predict'): | |
| features = [fixed_acidity, volatile_acidity, citric_acid, residual_sugar, chlorides, | |
| free_sulfur_dioxide, total_sulfur_dioxide, density, pH, sulphates, alcohol] | |
| predicted_quality = predict_quality(model, features) | |
| st.success(f'Predicted wine quality: {predicted_quality}') | |