harshiv's picture
Update app.py
bc2dd7a verified
import gradio as gr
import pandas as pd
import pickle
# Load the trained model from data.pkl
def load_model():
with open('data.pkl', 'rb') as file:
model = pickle.load(file)
return model
# Define the prediction function using the loaded model
def predict_user_profile(inputs):
# Preprocess the input data
# Create a DataFrame from the user input dictionary
df = pd.DataFrame.from_dict([inputs])
# Select the relevant feature columns used during model training
feature_columns_to_use = ['statuses_count', 'followers_count', 'friends_count',
'favourites_count', 'listed_count', 'lang_code']
df_features = df[feature_columns_to_use]
# Load the pre-trained model
model = load_model()
# Make predictions using the loaded model
prediction = model.predict(df_features)
# Return the predicted class label (0 for fake, 1 for genuine)
return "Genuine" if prediction[0] == 1 else "Fake"
# Define the Gradio interface
inputs = [
gr.Textbox(label="statuses_count"),
gr.Textbox(label="followers_count"),
gr.Textbox(label="friends_count"),
gr.Textbox(label="favourites_count"),
gr.Textbox(label="listed_count"),
gr.Textbox(label="name"),
gr.Textbox(label="Language"),
]
outputs = gr.Textbox(label="Prediction")
# Create the Gradio interface
interface = gr.Interface(fn=predict_user_profile, inputs=inputs, outputs=outputs,
title='User Profile Classifier',
description='Predict whether a user profile is genuine or fake.')
interface.launch(share=True)