|
import pandas as pd |
|
import pickle |
|
from sklearn.preprocessing import LabelEncoder |
|
import streamlit as st |
|
|
|
|
|
def load_model(): |
|
with open('data.pkl', 'rb') as file: |
|
model = pickle.load(file) |
|
return model |
|
|
|
|
|
def predict_user_profile(inputs): |
|
|
|
lang_encoder = LabelEncoder() |
|
lang_code = lang_encoder.fit_transform([inputs['Language']])[0] |
|
|
|
|
|
df = pd.DataFrame.from_dict([inputs]) |
|
|
|
|
|
feature_columns_to_use = ['statuses_count', 'followers_count', 'friends_count', |
|
'favourites_count', 'listed_count', 'lang_code'] |
|
df_features = df[feature_columns_to_use] |
|
|
|
|
|
model = load_model() |
|
|
|
|
|
prediction = model.predict(df_features) |
|
|
|
|
|
return "Genuine" if prediction[0] == 1 else "Fake" |
|
|
|
|
|
st.title('User Profile Classifier') |
|
st.write('Predict whether a user profile is genuine or fake.') |
|
|
|
|
|
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") |
|
|
|
|
|
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 |
|
} |
|
|
|
|
|
if st.button("Predict"): |
|
prediction = predict_user_profile(user_input) |
|
st.write(f"Prediction: {prediction}") |
|
|