Download app.py from shwetashweta05/Automatic_Machine_Learning_Project-1: direct link, hf CLI and curl.
- Browser
- Download file 2.96 kB
-
https://huggingface.co/spaces/shwetashweta05/Automatic_Machine_Learning_Project-1/resolve/main/app.py
- Command line
-
hf download hf://spaces/shwetashweta05/Automatic_Machine_Learning_Project-1/app.py
-
curl -L -o app.py https://huggingface.co/spaces/shwetashweta05/Automatic_Machine_Learning_Project-1/resolve/main/app.py
2.96 kB
| import streamlit as st | |
| import pickle | |
| import numpy as np | |
| import os | |
| # Define Model File Path | |
| model_path = "random_forest_pipeline.pkl" | |
| # Streamlit UI Setup | |
| st.set_page_config(page_title="Wine Quality Prediction π·π¬", layout="centered") | |
| # UI Styling | |
| st.markdown( | |
| """ | |
| <style> | |
| .stApp { background-color: #003366; color: white; } | |
| .title { font-size: 36px; font-weight: bold; color: white; text-align: center; } | |
| .subtitle { font-size: 24px; font-weight: bold; color: #ffcc00; } | |
| .stSelectbox label, .stNumberInput label, .stSlider label { font-size: 18px; font-weight: bold; color: white; } | |
| .stButton>button { background-color: #ffcc00; color: #003366; font-size: 18px; font-weight: bold; border-radius: 10px; } | |
| .stButton>button:hover { background-color: #ff9900; color: white; } | |
| .prediction { font-size: 26px; font-weight: bold; color: #32CD32; text-align: center; } | |
| </style> | |
| """, | |
| unsafe_allow_html=True, | |
| ) | |
| st.markdown('<h1 class="title">Wine Quality Prediction π·π¬</h1>', unsafe_allow_html=True) | |
| st.write("Predicting Wine Quality based on wine parameters.") | |
| # Check if model exists | |
| if os.path.exists(model_path): | |
| with open(model_path, "rb") as f: | |
| model = pickle.load(f) | |
| st.success("β Model loaded successfully!") | |
| model_loaded = True | |
| else: | |
| st.error(f"β Model file '{model_path}' not found! Please upload or train the model first.") | |
| model_loaded = False | |
| # User Inputs | |
| fixed_acidity = st.number_input("Fixed Acidity", min_value=4.6, max_value=15.9, value=7.6) | |
| volatile_acidity = st.number_input("Volatile Acidity", min_value=0.12, max_value=1.58, value=1.2) | |
| citric_acid = st.number_input("Citric Acid", min_value=0.0, max_value=1.66, value=0.5) | |
| residual_sugar = st.number_input("Residual Sugar", min_value=0.9, max_value=15.5, value=5.8) | |
| chlorides = st.number_input("Chlorides", min_value=0.012, max_value=0.611, value=0.044) | |
| free_sulfur_dioxide = st.slider("Free Sulfur Dioxide", 1, 72, 15) | |
| total_sulfur_dioxide = st.slider("Total Sulfur Dioxide", 6, 289, 100) | |
| density = st.number_input("Density", min_value=0.99007, max_value=1.00369, value=1.00111) | |
| pH = st.number_input("pH", min_value=2.74, max_value=4.01, value=3.12) | |
| sulphates = st.number_input("Sulphates", min_value=0.33, max_value=2.00, value=0.9) | |
| alcohol = st.number_input("Alcohol", min_value=8.4, max_value=14.9, value=10.2) | |
| # Prepare Input for Prediction | |
| 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 Wine Quality"): | |
| if model_loaded: | |
| prediction = model.predict(input_data) | |
| st.markdown(f'<p class="prediction">Predicted Wine Quality: {prediction[0]}</p>', unsafe_allow_html=True) | |
| else: | |
| st.error(f"β Model file '{model_path}' not found. Please train the model and try again.") | |