Spaces:
Sleeping
Sleeping
Upload 5 files
Browse files- Untitled.ipynb +195 -0
- Untitled1.ipynb +0 -0
- data.pkl +3 -0
- data/fusers.csv +0 -0
- data/users.csv +0 -0
Untitled.ipynb
ADDED
@@ -0,0 +1,195 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 2,
|
6 |
+
"id": "806d60dd-cc27-4d23-add1-7cd28bbaa0fa",
|
7 |
+
"metadata": {},
|
8 |
+
"outputs": [
|
9 |
+
{
|
10 |
+
"name": "stderr",
|
11 |
+
"output_type": "stream",
|
12 |
+
"text": [
|
13 |
+
"C:\\Users\\mistr\\anaconda3\\Lib\\site-packages\\gradio\\utils.py:953: UserWarning: Expected 1 arguments for function <function predict_user_profile at 0x000001DFE61E2840>, received 7.\n",
|
14 |
+
" warnings.warn(\n",
|
15 |
+
"C:\\Users\\mistr\\anaconda3\\Lib\\site-packages\\gradio\\utils.py:961: UserWarning: Expected maximum 1 arguments for function <function predict_user_profile at 0x000001DFE61E2840>, received 7.\n",
|
16 |
+
" warnings.warn(\n"
|
17 |
+
]
|
18 |
+
},
|
19 |
+
{
|
20 |
+
"name": "stdout",
|
21 |
+
"output_type": "stream",
|
22 |
+
"text": [
|
23 |
+
"Running on local URL: http://127.0.0.1:7861\n"
|
24 |
+
]
|
25 |
+
},
|
26 |
+
{
|
27 |
+
"name": "stderr",
|
28 |
+
"output_type": "stream",
|
29 |
+
"text": [
|
30 |
+
"Traceback (most recent call last):\n",
|
31 |
+
" File \"C:\\Users\\mistr\\anaconda3\\Lib\\site-packages\\gradio\\queueing.py\", line 527, in process_events\n",
|
32 |
+
" response = await route_utils.call_process_api(\n",
|
33 |
+
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
|
34 |
+
" File \"C:\\Users\\mistr\\anaconda3\\Lib\\site-packages\\gradio\\route_utils.py\", line 270, in call_process_api\n",
|
35 |
+
" output = await app.get_blocks().process_api(\n",
|
36 |
+
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
|
37 |
+
" File \"C:\\Users\\mistr\\anaconda3\\Lib\\site-packages\\gradio\\blocks.py\", line 1847, in process_api\n",
|
38 |
+
" result = await self.call_function(\n",
|
39 |
+
" ^^^^^^^^^^^^^^^^^^^^^^^^^\n",
|
40 |
+
" File \"C:\\Users\\mistr\\anaconda3\\Lib\\site-packages\\gradio\\blocks.py\", line 1433, in call_function\n",
|
41 |
+
" prediction = await anyio.to_thread.run_sync(\n",
|
42 |
+
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
|
43 |
+
" File \"C:\\Users\\mistr\\anaconda3\\Lib\\site-packages\\anyio\\to_thread.py\", line 56, in run_sync\n",
|
44 |
+
" return await get_async_backend().run_sync_in_worker_thread(\n",
|
45 |
+
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
|
46 |
+
" File \"C:\\Users\\mistr\\anaconda3\\Lib\\site-packages\\anyio\\_backends\\_asyncio.py\", line 2134, in run_sync_in_worker_thread\n",
|
47 |
+
" return await future\n",
|
48 |
+
" ^^^^^^^^^^^^\n",
|
49 |
+
" File \"C:\\Users\\mistr\\anaconda3\\Lib\\site-packages\\anyio\\_backends\\_asyncio.py\", line 851, in run\n",
|
50 |
+
" result = context.run(func, *args)\n",
|
51 |
+
" ^^^^^^^^^^^^^^^^^^^^^^^^\n",
|
52 |
+
" File \"C:\\Users\\mistr\\anaconda3\\Lib\\site-packages\\gradio\\utils.py\", line 788, in wrapper\n",
|
53 |
+
" response = f(*args, **kwargs)\n",
|
54 |
+
" ^^^^^^^^^^^^^^^^^^\n",
|
55 |
+
"TypeError: predict_user_profile() takes 1 positional argument but 7 were given\n"
|
56 |
+
]
|
57 |
+
},
|
58 |
+
{
|
59 |
+
"name": "stdout",
|
60 |
+
"output_type": "stream",
|
61 |
+
"text": [
|
62 |
+
"\n",
|
63 |
+
"Could not create share link. Missing file: C:\\Users\\mistr\\anaconda3\\Lib\\site-packages\\gradio\\frpc_windows_amd64_v0.2. \n",
|
64 |
+
"\n",
|
65 |
+
"Please check your internet connection. This can happen if your antivirus software blocks the download of this file. You can install manually by following these steps: \n",
|
66 |
+
"\n",
|
67 |
+
"1. Download this file: https://cdn-media.huggingface.co/frpc-gradio-0.2/frpc_windows_amd64.exe\n",
|
68 |
+
"2. Rename the downloaded file to: frpc_windows_amd64_v0.2\n",
|
69 |
+
"3. Move the file to this location: C:\\Users\\mistr\\anaconda3\\Lib\\site-packages\\gradio\n"
|
70 |
+
]
|
71 |
+
},
|
72 |
+
{
|
73 |
+
"data": {
|
74 |
+
"text/html": [
|
75 |
+
"<div><iframe src=\"http://127.0.0.1:7861/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
76 |
+
],
|
77 |
+
"text/plain": [
|
78 |
+
"<IPython.core.display.HTML object>"
|
79 |
+
]
|
80 |
+
},
|
81 |
+
"metadata": {},
|
82 |
+
"output_type": "display_data"
|
83 |
+
},
|
84 |
+
{
|
85 |
+
"data": {
|
86 |
+
"text/plain": []
|
87 |
+
},
|
88 |
+
"execution_count": 2,
|
89 |
+
"metadata": {},
|
90 |
+
"output_type": "execute_result"
|
91 |
+
}
|
92 |
+
],
|
93 |
+
"source": [
|
94 |
+
"import gradio as gr\n",
|
95 |
+
"import pandas as pd\n",
|
96 |
+
"import pickle\n",
|
97 |
+
"from sklearn.preprocessing import LabelEncoder\n",
|
98 |
+
"\n",
|
99 |
+
"# Load the trained model from data.pkl\n",
|
100 |
+
"def load_model():\n",
|
101 |
+
" with open('data.pkl', 'rb') as file:\n",
|
102 |
+
" model = pickle.load(file)\n",
|
103 |
+
" return model\n",
|
104 |
+
"\n",
|
105 |
+
"# Define the prediction function using the loaded model\n",
|
106 |
+
"def predict_user_profile(inputs):\n",
|
107 |
+
" # Preprocess the input data\n",
|
108 |
+
" lang_encoder = LabelEncoder()\n",
|
109 |
+
" lang_code = lang_encoder.fit_transform([inputs['Language']])[0]\n",
|
110 |
+
"\n",
|
111 |
+
" # Create a DataFrame from the user input dictionary\n",
|
112 |
+
" df = pd.DataFrame.from_dict([inputs])\n",
|
113 |
+
"\n",
|
114 |
+
" # Select the relevant feature columns used during model training\n",
|
115 |
+
" feature_columns_to_use = ['statuses_count', 'followers_count', 'friends_count',\n",
|
116 |
+
" 'favourites_count', 'listed_count', 'lang_code']\n",
|
117 |
+
" df_features = df[feature_columns_to_use]\n",
|
118 |
+
"\n",
|
119 |
+
" # Load the pre-trained model\n",
|
120 |
+
" model = load_model()\n",
|
121 |
+
"\n",
|
122 |
+
" # Make predictions using the loaded model\n",
|
123 |
+
" prediction = model.predict(df_features)\n",
|
124 |
+
"\n",
|
125 |
+
" # Return the predicted class label (0 for fake, 1 for genuine)\n",
|
126 |
+
" return \"Genuine\" if prediction[0] == 1 else \"Fake\"\n",
|
127 |
+
"\n",
|
128 |
+
"# Define the Gradio interface\n",
|
129 |
+
"inputs = [\n",
|
130 |
+
" gr.Textbox(label=\"statuses_count\"),\n",
|
131 |
+
" gr.Textbox(label=\"followers_count\"),\n",
|
132 |
+
" gr.Textbox(label=\"friends_count\"),\n",
|
133 |
+
" gr.Textbox(label=\"favourites_count\"),\n",
|
134 |
+
" gr.Textbox(label=\"listed_count\"),\n",
|
135 |
+
" gr.Textbox(label=\"name\"),\n",
|
136 |
+
" gr.Textbox(label=\"Language\"),\n",
|
137 |
+
"]\n",
|
138 |
+
"\n",
|
139 |
+
"outputs = gr.Textbox(label=\"Prediction\")\n",
|
140 |
+
"\n",
|
141 |
+
"# Create the Gradio interface\n",
|
142 |
+
"interface = gr.Interface(fn=predict_user_profile, inputs=inputs, outputs=outputs,\n",
|
143 |
+
" title='User Profile Classifier',\n",
|
144 |
+
" description='Predict whether a user profile is genuine or fake.')\n",
|
145 |
+
"\n",
|
146 |
+
"interface.launch(share=True)\n"
|
147 |
+
]
|
148 |
+
},
|
149 |
+
{
|
150 |
+
"cell_type": "code",
|
151 |
+
"execution_count": null,
|
152 |
+
"id": "02a483bc-0d49-45e5-908e-eab4769ac7af",
|
153 |
+
"metadata": {},
|
154 |
+
"outputs": [],
|
155 |
+
"source": []
|
156 |
+
},
|
157 |
+
{
|
158 |
+
"cell_type": "code",
|
159 |
+
"execution_count": null,
|
160 |
+
"id": "c1443145-496e-4cc4-a516-0ea70e4cc1fb",
|
161 |
+
"metadata": {},
|
162 |
+
"outputs": [],
|
163 |
+
"source": []
|
164 |
+
},
|
165 |
+
{
|
166 |
+
"cell_type": "code",
|
167 |
+
"execution_count": null,
|
168 |
+
"id": "58478763-b66d-4841-a965-089b1681b3c0",
|
169 |
+
"metadata": {},
|
170 |
+
"outputs": [],
|
171 |
+
"source": []
|
172 |
+
}
|
173 |
+
],
|
174 |
+
"metadata": {
|
175 |
+
"kernelspec": {
|
176 |
+
"display_name": "Python 3 (ipykernel)",
|
177 |
+
"language": "python",
|
178 |
+
"name": "python3"
|
179 |
+
},
|
180 |
+
"language_info": {
|
181 |
+
"codemirror_mode": {
|
182 |
+
"name": "ipython",
|
183 |
+
"version": 3
|
184 |
+
},
|
185 |
+
"file_extension": ".py",
|
186 |
+
"mimetype": "text/x-python",
|
187 |
+
"name": "python",
|
188 |
+
"nbconvert_exporter": "python",
|
189 |
+
"pygments_lexer": "ipython3",
|
190 |
+
"version": "3.11.7"
|
191 |
+
}
|
192 |
+
},
|
193 |
+
"nbformat": 4,
|
194 |
+
"nbformat_minor": 5
|
195 |
+
}
|
Untitled1.ipynb
ADDED
The diff for this file is too large to render.
See raw diff
|
|
data.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a7e7ed00f4b01521ea4119232c9f303cc42c77430fc2b4481340d24567a4f282
|
3 |
+
size 181103
|
data/fusers.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
data/users.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|