Spaces:
Sleeping
Sleeping
File size: 2,075 Bytes
957a109 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
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}")
|