Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,61 +1,43 @@
|
|
1 |
-
import pandas as pd
|
2 |
import pickle
|
|
|
3 |
import streamlit as st
|
4 |
-
# Load the trained model from data.pkl (assuming it's a custom model without sklearn)
|
5 |
-
def load_model():
|
6 |
-
with open('data.pkl', 'rb') as file:
|
7 |
-
model = pickle.load(file)
|
8 |
-
return model
|
9 |
-
|
10 |
-
# Define the prediction function using the loaded model
|
11 |
-
def predict_user_profile(inputs):
|
12 |
-
# Preprocess the input data (assuming your model doesn't require LabelEncoder)
|
13 |
-
# ... (modify this section based on your specific model's preprocessing needs)
|
14 |
-
|
15 |
-
# Create a DataFrame from the user input dictionary
|
16 |
-
df = pd.DataFrame.from_dict([inputs])
|
17 |
-
|
18 |
-
# Select the relevant feature columns used during model training
|
19 |
-
feature_columns_to_use = ['statuses_count', 'followers_count', 'friends_count',
|
20 |
-
'favourites_count','listed_count'] # Assuming language isn't used
|
21 |
-
df_features = df[feature_columns_to_use]
|
22 |
-
|
23 |
-
# Load the pre-trained model
|
24 |
-
model = load_model()
|
25 |
-
|
26 |
-
# Make predictions using the loaded model (assuming your model has a predict method)
|
27 |
-
prediction = model.predict(df_features)
|
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 |
# Predict if the user clicks the button
|
59 |
-
if st.button("
|
60 |
-
prediction =
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import pickle
|
2 |
+
import pandas as pd
|
3 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
+
# Load the trained model
|
6 |
+
model = pickle.load(open("data.pkl", "rb"))
|
7 |
+
|
8 |
+
# Define a function to predict user data
|
9 |
+
def predict_user_data(user_data):
|
10 |
+
user_df = pd.DataFrame(user_data, index=[0])
|
11 |
+
user_df = extract_features(user_df) # Assuming the extract_features function is defined elsewhere in your code
|
12 |
+
prediction = model.predict(user_df)[0]
|
13 |
+
return prediction
|
14 |
+
|
15 |
+
# Streamlit app layout
|
16 |
+
st.title("Fake or Genuine User Classifier")
|
17 |
+
|
18 |
+
# Get user input
|
19 |
+
user_statuses_count = st.number_input("Statuses Count", min_value=0)
|
20 |
+
user_followers_count = st.number_input("Followers Count", min_value=0)
|
21 |
+
user_friends_count = st.number_input("Friends Count", min_value=0)
|
22 |
+
user_favourites_count = st.number_input("Favourites Count", min_value=0)
|
23 |
+
user_listed_count = st.number_input("Listed Count", min_value=0)
|
24 |
+
user_name = st.text_input("Name")
|
25 |
+
|
26 |
+
# Get user input as a dictionary
|
27 |
+
user_data = {
|
28 |
+
"statuses_count": user_statuses_count,
|
29 |
+
"followers_count": user_followers_count,
|
30 |
+
"friends_count": user_friends_count,
|
31 |
+
"favourites_count": user_favourites_count,
|
32 |
+
"listed_count": user_listed_count,
|
33 |
+
"name": user_name,
|
34 |
}
|
35 |
|
36 |
# Predict if the user clicks the button
|
37 |
+
if st.button("Classify User"):
|
38 |
+
prediction = predict_user_data(user_data)
|
39 |
+
if prediction == 1:
|
40 |
+
st.success("The user is likely Genuine.")
|
41 |
+
else:
|
42 |
+
st.warning("The user is likely Fake.")
|
43 |
+
|