Spaces:
Sleeping
Sleeping
import pandas as pd | |
import pickle | |
from sklearn.preprocessing import LabelEncoder | |
import streamlit as st | |
# 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 | |
lang_encoder = LabelEncoder() | |
lang_code = lang_encoder.fit_transform([inputs['Language']])[0] | |
# 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" | |
# Create the Streamlit app | |
st.title('User Profile Classifier') | |
st.write('Predict whether a user profile is genuine or fake.') | |
# Create input fields for user data | |
statuses_count = st.number_input("Statuses Count", min_value=0) | |
followers_count = st.number_input("Followers Count", min_value=0) | |
friends_count = st.number_input("Friends Count", min_value=0) | |
favourites_count = st.number_input("Favourites Count", min_value=0) | |
listed_count = st.number_input("Listed Count", min_value=0) | |
name = st.text_input("Name") | |
language = st.text_input("Language") | |
# Create a dictionary to store user inputs | |
user_input = { | |
"statuses_count": statuses_count, | |
"followers_count": followers_count, | |
"friends_count": friends_count, | |
"favourites_count": favourites_count, | |
"listed_count": listed_count, | |
"name": name, | |
"Language": language | |
} | |
# Predict if the user clicks the button | |
if st.button("Predict"): | |
prediction = predict_user_profile(user_input) | |
st.write(f"Prediction: {prediction}") | |