harshiv commited on
Commit
957a109
1 Parent(s): 0307615

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -0
app.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)
10
+ return model
11
+
12
+ # Define the prediction function using the loaded model
13
+ def predict_user_profile(inputs):
14
+ # Preprocess the input data
15
+ lang_encoder = LabelEncoder()
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', 'lang_code']
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 (0 for fake, 1 for genuine)
33
+ return "Genuine" if prediction[0] == 1 else "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
+ language = st.text_input("Language")
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
+ "Language": language
57
+ }
58
+
59
+ # Predict if the user clicks the button
60
+ if st.button("Predict"):
61
+ prediction = predict_user_profile(user_input)
62
+ st.write(f"Prediction: {prediction}")