import gradio as gr import joblib import numpy as np # Load the saved model and scaler model = joblib.load('best_random_forest_model.pkl') scaler = joblib.load('scaler.pkl') def predict_house_price(feature1, feature2, feature3, feature4, feature5): # Combine all features into a single list features = [feature1, feature2, feature3, feature4, feature5] # Scale the input features using the saved scaler scaled_features = scaler.transform([features]) # Make predictions using the loaded model prediction = model.predict(scaled_features) return f"Predicted House Price: ${prediction[0]:,.2f}" # Create the Gradio interface interface = gr.Interface( fn=predict_house_price, inputs=[ gr.Number(label="Feature 1: (e.g., Average number of rooms per dwelling)"), gr.Number(label="Feature 2: (e.g., Total rooms)"), gr.Number(label="Feature 3: (e.g., Total bedrooms)"), gr.Number(label="Feature 4: (e.g., Median age of houses)"), gr.Number(label="Feature 5: (e.g., Population)"), ], outputs=gr.Textbox(label="Predicted House Price"), description="Predict California house prices based on input features.", title="California House Price Predictor" ) # Launch the Gradio app interface.launch()