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)