Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import joblib | |
| import numpy as np | |
| import pandas as pd | |
| from huggingface_hub import hf_hub_download | |
| # Load the trained model and scaler objects from file | |
| REPO_ID = "Hemg/marketforecast" # hugging face repo ID | |
| MoDEL_FILENAME = "market.joblib" # model file name | |
| SCALER_FILENAME ="marketscaler.joblib" # scaler file name | |
| model = joblib.load(hf_hub_download(repo_id=REPO_ID, filename=MoDEL_FILENAME)) | |
| scaler = joblib.load(hf_hub_download(repo_id=REPO_ID, filename=SCALER_FILENAME)) | |
| # model = joblib.load('D:\gradioapp\X.joblib') | |
| # scaler = joblib.load('D:\gradioapp\Xx.joblib') | |
| # Define the prediction function | |
| def predict_enrol(Year, Instagram_Advertising, Facebook_Advertising, Event_Expenses, | |
| Internet_Expenses, Facebook_Enroll, Instagram_Enroll, Internet_Enroll, | |
| Recommendation, Total_Expenses): | |
| # Prepare input data | |
| input_data = [[Year, Instagram_Advertising, Facebook_Advertising, Event_Expenses, | |
| Internet_Expenses, Facebook_Enroll, Instagram_Enroll, Internet_Enroll, | |
| Recommendation, Total_Expenses]] | |
| # Get the feature names from the Gradio interface inputs | |
| feature_names = ["Year", "Instagram Advertising", "Facebook Advertising", | |
| "Event Expenses", "Internet Expenses", "Facebook Enroll", | |
| "Instagram Enroll", "Internet Enroll", "Recommendation", | |
| "Total Expenses"] | |
| # Create a Pandas DataFrame with the input data and feature names | |
| input_df = pd.DataFrame(input_data, columns=feature_names) | |
| # Scale the input data using the loaded scaler | |
| scaled_input = scaler.transform(input_df) | |
| # Make predictions using the loaded model | |
| prediction = model.predict(scaled_input)[0] | |
| return f"Predicted House Price: ${prediction:,.2f}" # Price is our dependent variable | |
| # Create the Gradio app | |
| iface = gr.Interface( | |
| fn=predict_enrol, | |
| inputs=[ | |
| gr.Number(label="Year"), | |
| gr.Number(label="Instagram Advertising"), | |
| gr.Number(label="Facebook Advertising"), | |
| gr.Number(label="Event Expenses"), | |
| gr.Number(label="Internet Expenses"), | |
| gr.Number(label="Facebook Enroll"), | |
| gr.Number(label="Instagram Enroll"), | |
| gr.Number(label="Internet Enroll"), | |
| gr.Number(label="Recommendation"), | |
| gr.Number(label="Total Enroll"), | |
| ], | |
| outputs="text", | |
| title="marketforecast", | |
| description="Predict market" | |
| ) | |
| # Run the app | |
| if __name__ == "__main__": | |
| iface.launch(share=True) |