Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
import pickle
|
4 |
+
from sklearn.preprocessing import LabelEncoder
|
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 |
+
# Define the Gradio interface
|
36 |
+
inputs = [
|
37 |
+
gr.Textbox(label="statuses_count"),
|
38 |
+
gr.Textbox(label="followers_count"),
|
39 |
+
gr.Textbox(label="friends_count"),
|
40 |
+
gr.Textbox(label="favourites_count"),
|
41 |
+
gr.Textbox(label="listed_count"),
|
42 |
+
gr.Textbox(label="name"),
|
43 |
+
gr.Textbox(label="Language"),
|
44 |
+
]
|
45 |
+
|
46 |
+
outputs = gr.Textbox(label="Prediction")
|
47 |
+
|
48 |
+
# Create the Gradio interface
|
49 |
+
interface = gr.Interface(fn=predict_user_profile, inputs=inputs, outputs=outputs,
|
50 |
+
title='User Profile Classifier',
|
51 |
+
description='Predict whether a user profile is genuine or fake.')
|
52 |
+
|