import gradio as gr import joblib import numpy as np import pandas as pd # Load the model and unique brand values model = joblib.load('model.joblib') # Define the prediction function def predict(fixed_acidity,volatile_acidity,citric_acid,residual_sugar,chlorides,free_sulfur_dioxide,total_sulfur_dioxide,density,pH,sulphates,alcohol): # Convert inputs to appropriate types fixed_acidity = float(fixed_acidity) volatile_acidity = float(volatile_acidity) citric_acid = float(citric_acid) residual_sugar = float(residual_sugar) chlorides = float(chlorides) free_sulfur_dioxide = float(free_sulfur_dioxide) total_sulfur_dioxide = float(total_sulfur_dioxide) density = float(density) pH = float(pH) sulphates = float(sulphates) alcohol = float(alcohol) # Prepare the input array for prediction input_data = pd.DataFrame({ 'fixed_acidity': [fixed_acidity], 'volatile_acidity': [volatile_acidity], 'citric_acid': [citric_acid], 'residual_sugar': [residual_sugar], 'chlorides': [chlorides], 'free_sulfur_dioxide': [free_sulfur_dioxide], 'total_sulfur_dioxide': [total_sulfur_dioxide], 'density': [density], 'pH': [pH], 'sulphates': [sulphates], 'alcohol': [alcohol] }) # Perform the prediction prediction = model.predict(input_data) return str(int(prediction[0])) # Create the Gradio interface interface = gr.Interface( fn=predict, inputs=[ gr.Textbox(label="Fixed_Acidity"), gr.Textbox(label="Volatile_Acidity"), gr.Textbox(label="Citric_Acid"), gr.Textbox(label="Residual_Sugar"), gr.Textbox(label="Chlorides"), gr.Textbox(label="Free_Sulfur_Dioxide"), gr.Textbox(label="Total_Sulfur_Dioxide"), gr.Textbox(label="Density"), gr.Textbox(label="pH"), gr.Textbox(label="Sulphates"), gr.Textbox(label="Alcohol") ], outputs="text", title="Wine Quality Predictor", description="Enter the values for the following features to predict the wine quality." ) # Launch the interface interface.launch()