Michelangiolo commited on
Commit
5f36b0b
1 Parent(s): b24850f

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -0
app.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ os.system('pip install openpyxl')
3
+ os.system('pip install sentence-transformers')
4
+ import pandas as pd
5
+ from sentence_transformers import SentenceTransformer
6
+
7
+ model = SentenceTransformer('all-mpnet-base-v2') #all-MiniLM-L6-v2 #all-mpnet-base-v2
8
+
9
+ df = pd.read_parquet('df_encoded.parquet')
10
+ df
11
+
12
+ from sklearn.neighbors import NearestNeighbors
13
+ import numpy as np
14
+ import pandas as pd
15
+
16
+ from sentence_transformers import SentenceTransformer
17
+
18
+ model = SentenceTransformer('all-mpnet-base-v2') #all-MiniLM-L6-v2 #all-mpnet-base-v2
19
+
20
+ #prepare model
21
+ # nbrs = NearestNeighbors(n_neighbors=8, algorithm='ball_tree').fit(df['text_vector_'].values.tolist())
22
+
23
+ def filter_df(df, column_name, filter_type, filter_value):
24
+ if filter_type == '==':
25
+ df_filtered = df[df[column_name]==filter_value]
26
+ elif filter_type == '<=':
27
+ df_filtered = df[df[column_name]<=filter_value]
28
+ return df_filtered
29
+
30
+ def search(df, query):
31
+ product = model.encode(query).tolist()
32
+ # product = df.iloc[0]['text_vector_'] #use one of the products as sample
33
+
34
+ nbrs = NearestNeighbors(n_neighbors=8, algorithm='ball_tree').fit(df['text_vector_'].values.tolist())
35
+ distances, indices = nbrs.kneighbors([product]) #input the vector of the reference object
36
+
37
+ #print out the description of every recommended product
38
+ df_search = df.iloc[list(indices)[0]].drop(['skills', 'text_vector_'], axis=1).sort_values('avgFeedbackScore', ascending=False)
39
+
40
+ return df_search[['shortName', 'location', 'title', 'hourlyRate', 'avgFeedbackScore', 'description']]
41
+
42
+ # search('I want to hire a person who does both backend and')
43
+
44
+ df_location = filter_df(df, 'location', '==', 'New York')
45
+ df_price = filter_df(df_location, 'hourlyRate', '<=', 80)
46
+ search(df_price, 'I want to hire a person who does both backend and')
47
+
48
+ import gradio as gr
49
+ import os
50
+
51
+ #the first module becomes text1, the second module file1
52
+ def greet(price, location, query):
53
+ # df1 =
54
+ df_location = filter_df(df, 'location', '==', location)
55
+ df_price = filter_df(df_location, 'hourlyRate', '<=', price)
56
+ df_search = search(df_price, query)
57
+ return df_search
58
+
59
+ with gr.Blocks(theme=gr.themes.Soft(primary_hue='amber', secondary_hue='gray', neutral_hue='amber')) as demo:
60
+ gr.Markdown(
61
+ """
62
+ # Freelancer Upwork Search
63
+ """
64
+ )
65
+ input1 = gr.Slider(20, 120, value=90, step_size=5, label="Max Hourly Rate")
66
+ input2 = gr.Radio(['New York', 'Chicago', 'Washington'], multiselect=False, label='State', value='New York')
67
+ input3 = gr.Textbox(label='Query', value='I want to develop a mobile app')
68
+
69
+ btn = gr.Button(value="Search for Product")
70
+ output = gr.Dataframe()
71
+ # btn.click(greet, inputs='text', outputs=['dataframe'])
72
+ btn.click(greet, [input1, input2, input3], [output])
73
+ demo.launch(share=True)