Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,7 @@
|
|
1 |
import pandas as pd
|
2 |
import pickle
|
3 |
-
from sklearn.preprocessing import LabelEncoder
|
4 |
-
import streamlit as st
|
5 |
|
6 |
-
# Load the trained model from data.pkl
|
7 |
def load_model():
|
8 |
with open('data.pkl', 'rb') as file:
|
9 |
model = pickle.load(file)
|
@@ -11,26 +9,28 @@ def load_model():
|
|
11 |
|
12 |
# Define the prediction function using the loaded model
|
13 |
def predict_user_profile(inputs):
|
14 |
-
# Preprocess the input data
|
15 |
-
|
16 |
-
lang_code = lang_encoder.fit_transform([inputs['Language']])[0]
|
17 |
|
18 |
# Create a DataFrame from the user input dictionary
|
19 |
df = pd.DataFrame.from_dict([inputs])
|
20 |
|
21 |
# Select the relevant feature columns used during model training
|
22 |
feature_columns_to_use = ['statuses_count', 'followers_count', 'friends_count',
|
23 |
-
'favourites_count', 'listed_count'
|
24 |
df_features = df[feature_columns_to_use]
|
25 |
|
26 |
# Load the pre-trained model
|
27 |
model = load_model()
|
28 |
|
29 |
-
# Make predictions using the loaded model
|
30 |
prediction = model.predict(df_features)
|
31 |
|
32 |
-
# Return the predicted class label (
|
33 |
-
|
|
|
|
|
|
|
34 |
|
35 |
# Create the Streamlit app
|
36 |
st.title('User Profile Classifier')
|
@@ -43,7 +43,7 @@ friends_count = st.number_input("Friends Count", min_value=0)
|
|
43 |
favourites_count = st.number_input("Favourites Count", min_value=0)
|
44 |
listed_count = st.number_input("Listed Count", min_value=0)
|
45 |
name = st.text_input("Name")
|
46 |
-
language
|
47 |
|
48 |
# Create a dictionary to store user inputs
|
49 |
user_input = {
|
@@ -53,7 +53,6 @@ user_input = {
|
|
53 |
"favourites_count": favourites_count,
|
54 |
"listed_count": listed_count,
|
55 |
"name": name,
|
56 |
-
"Language": language
|
57 |
}
|
58 |
|
59 |
# Predict if the user clicks the button
|
|
|
1 |
import pandas as pd
|
2 |
import pickle
|
|
|
|
|
3 |
|
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)
|
|
|
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 |
+
# Return the predicted class label (modify based on your model's output)
|
30 |
+
if prediction > 0.5: # Assuming a threshold for genuine classification
|
31 |
+
return "Genuine"
|
32 |
+
else:
|
33 |
+
return "Fake"
|
34 |
|
35 |
# Create the Streamlit app
|
36 |
st.title('User Profile Classifier')
|
|
|
43 |
favourites_count = st.number_input("Favourites Count", min_value=0)
|
44 |
listed_count = st.number_input("Listed Count", min_value=0)
|
45 |
name = st.text_input("Name")
|
46 |
+
# Remove language input since it's not used in this version
|
47 |
|
48 |
# Create a dictionary to store user inputs
|
49 |
user_input = {
|
|
|
53 |
"favourites_count": favourites_count,
|
54 |
"listed_count": listed_count,
|
55 |
"name": name,
|
|
|
56 |
}
|
57 |
|
58 |
# Predict if the user clicks the button
|