Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import joblib | |
| import pandas as pd | |
| # Load trained model | |
| model = joblib.load("wine_rf_model.pkl") | |
| # Define prediction function | |
| def predict(fixed_acidity, volatile_acidity, citric_acid, residual_sugar, chlorides, | |
| free_sulfur_dioxide, total_sulfur_dioxide, density, pH, sulphates, alcohol): | |
| data = pd.DataFrame([[fixed_acidity, volatile_acidity, citric_acid, residual_sugar, chlorides, | |
| free_sulfur_dioxide, total_sulfur_dioxide, density, pH, sulphates, alcohol]], | |
| columns=["fixed acidity", "volatile acidity", "citric acid", "residual sugar", | |
| "chlorides", "free sulfur dioxide", "total sulfur dioxide", "density", | |
| "pH", "sulphates", "alcohol"]) | |
| prediction = model.predict(data)[0] | |
| return f"Predicted Wine Quality: {prediction}" | |
| # Create Gradio interface | |
| iface = gr.Interface( | |
| fn=predict, | |
| inputs=[ | |
| gr.Number(label="Fixed Acidity"), | |
| gr.Number(label="Volatile Acidity"), | |
| gr.Number(label="Citric Acid"), | |
| gr.Number(label="Residual Sugar"), | |
| gr.Number(label="Chlorides"), | |
| gr.Number(label="Free Sulfur Dioxide"), | |
| gr.Number(label="Total Sulfur Dioxide"), | |
| gr.Number(label="Density"), | |
| gr.Number(label="pH"), | |
| gr.Number(label="Sulphates"), | |
| gr.Number(label="Alcohol") | |
| ], | |
| outputs=gr.Textbox(label="Prediction"), | |
| title="Wine Quality Prediction using Random Forest", | |
| description="Enter chemical properties of wine to predict its quality." | |
| ) | |
| iface.launch() | |