File size: 2,791 Bytes
5f36b0b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
os.system('pip install openpyxl')
os.system('pip install sentence-transformers')
import pandas as pd
from sentence_transformers import SentenceTransformer

model = SentenceTransformer('all-mpnet-base-v2') #all-MiniLM-L6-v2 #all-mpnet-base-v2

df = pd.read_parquet('df_encoded.parquet')
df

from sklearn.neighbors import NearestNeighbors
import numpy as np
import pandas as pd

from sentence_transformers import SentenceTransformer

model = SentenceTransformer('all-mpnet-base-v2') #all-MiniLM-L6-v2 #all-mpnet-base-v2

#prepare model
# nbrs = NearestNeighbors(n_neighbors=8, algorithm='ball_tree').fit(df['text_vector_'].values.tolist())

def filter_df(df, column_name, filter_type, filter_value):
    if filter_type == '==':
        df_filtered = df[df[column_name]==filter_value]
    elif filter_type == '<=':
        df_filtered = df[df[column_name]<=filter_value]
    return df_filtered

def search(df, query):
    product = model.encode(query).tolist()
    # product = df.iloc[0]['text_vector_'] #use one of the products as sample

    nbrs = NearestNeighbors(n_neighbors=8, algorithm='ball_tree').fit(df['text_vector_'].values.tolist())
    distances, indices = nbrs.kneighbors([product]) #input the vector of the reference object

    #print out the description of every recommended product
    df_search = df.iloc[list(indices)[0]].drop(['skills', 'text_vector_'], axis=1).sort_values('avgFeedbackScore', ascending=False)

    return df_search[['shortName', 'location', 'title', 'hourlyRate', 'avgFeedbackScore', 'description']]

# search('I want to hire a person who does both backend and')

df_location = filter_df(df, 'location', '==', 'New York')
df_price = filter_df(df_location, 'hourlyRate', '<=', 80)
search(df_price, 'I want to hire a person who does both backend and')

import gradio as gr
import os

#the first module becomes text1, the second module file1
def greet(price, location, query):
    # df1 = 
    df_location = filter_df(df, 'location', '==', location)
    df_price = filter_df(df_location, 'hourlyRate', '<=', price)
    df_search = search(df_price, query)
    return df_search

with gr.Blocks(theme=gr.themes.Soft(primary_hue='amber', secondary_hue='gray', neutral_hue='amber')) as demo:
    gr.Markdown(
    """
    # Freelancer Upwork Search
    """
    )
    input1 = gr.Slider(20, 120, value=90, step_size=5, label="Max Hourly Rate")
    input2 = gr.Radio(['New York', 'Chicago', 'Washington'], multiselect=False, label='State', value='New York')
    input3 = gr.Textbox(label='Query', value='I want to develop a mobile app')

    btn = gr.Button(value="Search for Product")
    output = gr.Dataframe()
    # btn.click(greet, inputs='text', outputs=['dataframe'])
    btn.click(greet, [input1, input2, input3], [output])
demo.launch(share=True)