Spaces:
Runtime error
Runtime error
File size: 13,035 Bytes
5911b8c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# !pip install sentence-transformers==2.0.0"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\Users\\ardit\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\torch\\onnx\\_internal\\_beartype.py:30: UserWarning: module 'beartype.roar' has no attribute 'BeartypeDecorHintPep585DeprecationWarning'\n",
" warnings.warn(f\"{e}\")\n"
]
}
],
"source": [
"import pandas as pd\n",
"from tqdm import tqdm\n",
"from sentence_transformers import SentenceTransformer\n",
"\n",
"model = SentenceTransformer('all-mpnet-base-v2') #all-MiniLM-L6-v2 #all-mpnet-base-v2"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df = pd.read_parquet('df_encoded.parquet')\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.neighbors import NearestNeighbors\n",
"import numpy as np\n",
"import pandas as pd\n",
"\n",
"from sentence_transformers import SentenceTransformer\n",
"\n",
"model = SentenceTransformer('all-mpnet-base-v2') #all-MiniLM-L6-v2 #all-mpnet-base-v2\n",
"\n",
"#prepare model\n",
"# nbrs = NearestNeighbors(n_neighbors=8, algorithm='ball_tree').fit(df['text_vector_'].values.tolist())"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>shortName</th>\n",
" <th>location</th>\n",
" <th>title</th>\n",
" <th>hourlyRate</th>\n",
" <th>avgFeedbackScore</th>\n",
" <th>description</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>3761</th>\n",
" <td>Steven F.</td>\n",
" <td>New York</td>\n",
" <td>Database Manger / Graphics / Social Media</td>\n",
" <td>35.0</td>\n",
" <td>4.939631</td>\n",
" <td>A highly skilled problem solver with over 10 ...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>835</th>\n",
" <td>Jacquelyn N.</td>\n",
" <td>New York</td>\n",
" <td>Admin support specialist</td>\n",
" <td>12.0</td>\n",
" <td>4.920992</td>\n",
" <td>I am a Kansas City based Virtual Assistant. I ...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2787</th>\n",
" <td>Mark H.</td>\n",
" <td>New York</td>\n",
" <td>WordPress Specialist - Development, Administra...</td>\n",
" <td>60.0</td>\n",
" <td>4.751762</td>\n",
" <td>Top Rated Plus | Specialize in WordPress | Inv...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3402</th>\n",
" <td>Carleton C.</td>\n",
" <td>New York</td>\n",
" <td>Expert freelancer with skills in Divi theme, C...</td>\n",
" <td>25.0</td>\n",
" <td>4.692159</td>\n",
" <td>For over 30 years, I have developed a wide ran...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1156</th>\n",
" <td>Andee F.</td>\n",
" <td>New York</td>\n",
" <td>Experienced Freelancer</td>\n",
" <td>15.0</td>\n",
" <td>4.645855</td>\n",
" <td>I have 8+ years of successfully providing admi...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1556</th>\n",
" <td>Laura O.</td>\n",
" <td>New York</td>\n",
" <td>Admin Expert with experience in Microsoft Suit...</td>\n",
" <td>30.0</td>\n",
" <td>4.620818</td>\n",
" <td>I have been passionate about my personal budge...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1002</th>\n",
" <td>Nicole H.</td>\n",
" <td>New York</td>\n",
" <td>Experienced admin support and customer support...</td>\n",
" <td>30.0</td>\n",
" <td>4.129972</td>\n",
" <td>I'm an experienced jack of all trades. I have...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1626</th>\n",
" <td>Drew L.</td>\n",
" <td>New York</td>\n",
" <td>Front End Web Developer</td>\n",
" <td>50.0</td>\n",
" <td>0.000000</td>\n",
" <td>Worked for agency with big name clients doing ...</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" shortName location \\\n",
"3761 Steven F. New York \n",
"835 Jacquelyn N. New York \n",
"2787 Mark H. New York \n",
"3402 Carleton C. New York \n",
"1156 Andee F. New York \n",
"1556 Laura O. New York \n",
"1002 Nicole H. New York \n",
"1626 Drew L. New York \n",
"\n",
" title hourlyRate \\\n",
"3761 Database Manger / Graphics / Social Media 35.0 \n",
"835 Admin support specialist 12.0 \n",
"2787 WordPress Specialist - Development, Administra... 60.0 \n",
"3402 Expert freelancer with skills in Divi theme, C... 25.0 \n",
"1156 Experienced Freelancer 15.0 \n",
"1556 Admin Expert with experience in Microsoft Suit... 30.0 \n",
"1002 Experienced admin support and customer support... 30.0 \n",
"1626 Front End Web Developer 50.0 \n",
"\n",
" avgFeedbackScore description \n",
"3761 4.939631 A highly skilled problem solver with over 10 ... \n",
"835 4.920992 I am a Kansas City based Virtual Assistant. I ... \n",
"2787 4.751762 Top Rated Plus | Specialize in WordPress | Inv... \n",
"3402 4.692159 For over 30 years, I have developed a wide ran... \n",
"1156 4.645855 I have 8+ years of successfully providing admi... \n",
"1556 4.620818 I have been passionate about my personal budge... \n",
"1002 4.129972 I'm an experienced jack of all trades. I have... \n",
"1626 0.000000 Worked for agency with big name clients doing ... "
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def filter_df(df, column_name, filter_type, filter_value):\n",
" if filter_type == '==':\n",
" df_filtered = df[df[column_name]==filter_value]\n",
" elif filter_type == '<=':\n",
" df_filtered = df[df[column_name]<=filter_value]\n",
" return df_filtered\n",
"\n",
"def search(df, query):\n",
" product = model.encode(query).tolist()\n",
" # product = df.iloc[0]['text_vector_'] #use one of the products as sample\n",
"\n",
" nbrs = NearestNeighbors(n_neighbors=8, algorithm='ball_tree').fit(df['text_vector_'].values.tolist())\n",
" distances, indices = nbrs.kneighbors([product]) #input the vector of the reference object\n",
"\n",
" #print out the description of every recommended product\n",
" df_search = df.iloc[list(indices)[0]].drop(['skills', 'text_vector_'], axis=1).sort_values('avgFeedbackScore', ascending=False)\n",
"\n",
" return df_search[['shortName', 'location', 'title', 'hourlyRate', 'avgFeedbackScore', 'description']]\n",
"\n",
"# search('I want to hire a person who does both backend and')\n",
"\n",
"df_location = filter_df(df, 'location', '==', 'New York')\n",
"df_price = filter_df(df_location, 'hourlyRate', '<=', 80)\n",
"search(df_price, 'I want to hire a person who does both backend and')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import gradio as gr\n",
"import os\n",
"\n",
"#the first module becomes text1, the second module file1\n",
"def greet(price, location, query):\n",
" # df1 = \n",
" df_location = filter_df(df, 'location', '==', location)\n",
" df_price = filter_df(df_location, 'hourlyRate', '<=', price)\n",
" df_search = search(df_price, query)\n",
" return df_search"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\Users\\ardit\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\gradio\\deprecation.py:43: UserWarning: You have unused kwarg parameters in Slider, please remove them: {'step_size': 5}\n",
" warnings.warn(\n",
"c:\\Users\\ardit\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\gradio\\deprecation.py:43: UserWarning: You have unused kwarg parameters in Radio, please remove them: {'multiselect': False}\n",
" warnings.warn(\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Running on local URL: http://127.0.0.1:7906\n",
"\n",
"To create a public link, set `share=True` in `launch()`.\n"
]
},
{
"data": {
"text/html": [
"<div><iframe src=\"http://127.0.0.1:7906/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": []
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"with gr.Blocks(theme=gr.themes.Soft(primary_hue='amber', secondary_hue='gray', neutral_hue='amber')) as demo:\n",
" gr.Markdown(\n",
" \"\"\"\n",
" # Freelancer Upwork Search\n",
" \"\"\"\n",
" )\n",
" input1 = gr.Slider(20, 120, value=90, step_size=5, label=\"Max Hourly Rate\")\n",
" input2 = gr.Radio(['New York', 'Chicago', 'Washington'], multiselect=False, label='State', value='New York')\n",
" input3 = gr.Textbox(label='Query', value='I want to develop a mobile app')\n",
"\n",
" btn = gr.Button(value=\"Search for Product\")\n",
" output = gr.Dataframe()\n",
" # btn.click(greet, inputs='text', outputs=['dataframe'])\n",
" btn.click(greet, [input1, input2, input3], [output])\n",
"demo.launch(share=False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# iface = gr.Interface(\n",
"# fn=greet,\n",
"# inputs=[\n",
"# gr.Slider(20, 120, value=20, step_size=5, label=\"Max Hourly Rate\"),\n",
"# gr.Radio(\n",
"# ['New York', 'Chicago', 'Washington'], multiselect=False, label='State', value='New York'\n",
"# ),\n",
"# gr.Textbox(label='Input', value='I want to develop a mobile app')\n",
"# ],\n",
"# outputs=[\"dataframe\"])\n",
"# iface.launch(share=False)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.9.0 64-bit",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "fdf377d643bc1cb065454f0ad2ceac75d834452ecf289e7ba92c6b3f59a7cee1"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
|