Ravishankarsharma's picture
Update app.py
fadd01e verified
# app.py
import gradio as gr
import pandas as pd
import pickle
import numpy as np
# Load your XGBoost model
with open("xgboost_facebook_model.pkl", "rb") as f:
model = pickle.load(f)
# Prediction function
def predict_engagement(f1, f2, f3, f4, f5, f6, f7, f8):
# Convert input features into 2D DataFrame
input_data = pd.DataFrame([[f1, f2, f3, f4, f5, f6, f7, f8]],
columns=['Feature1','Feature2','Feature3','Feature4',
'Feature5','Feature6','Feature7','Feature8'])
# Make prediction
pred = model.predict(input_data)[0]
return pred
# Gradio interface
iface = gr.Interface(
fn=predict_engagement,
inputs=[
gr.Number(label="Feature 1"),
gr.Number(label="Feature 2"),
gr.Number(label="Feature 3"),
gr.Number(label="Feature 4"),
gr.Number(label="Feature 5"),
gr.Number(label="Feature 6"),
gr.Number(label="Feature 7"),
gr.Number(label="Feature 8")
],
outputs=gr.Textbox(label="Predicted Engagement"),
title="XGBoost Engagement Predictor",
description="Input 8 numerical features to predict engagement using your XGBoost model."
)
if __name__ == "__main__":
iface.launch()