harshiv commited on
Commit
34f76c4
1 Parent(s): 86be394

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -55
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
- # 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')
37
- st.write('Predict whether a user profile is genuine or fake.')
38
-
39
- # Create input fields for user data
40
- statuses_count = st.number_input("Statuses Count", min_value=0)
41
- followers_count = st.number_input("Followers Count", min_value=0)
42
- 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
- # Remove language input since it's not used in this version
47
-
48
- # Create a dictionary to store user inputs
49
- user_input = {
50
- "statuses_count": statuses_count,
51
- "followers_count": followers_count,
52
- "friends_count": friends_count,
53
- "favourites_count": favourites_count,
54
- "listed_count": listed_count,
55
- "name": name,
 
 
56
  }
57
 
58
  # Predict if the user clicks the button
59
- if st.button("Predict"):
60
- prediction = predict_user_profile(user_input)
61
- st.write(f"Prediction: {prediction}")
 
 
 
 
 
 
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
+