Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -4,26 +4,18 @@ import time
|
|
| 4 |
|
| 5 |
import gradio as gr
|
| 6 |
from transformers import AutoTokenizer, AutoModel
|
| 7 |
-
import openai
|
| 8 |
# pytorch library
|
| 9 |
import torch
|
| 10 |
import torch.nn.functional as f
|
| 11 |
|
| 12 |
-
from fuzzywuzzy import process
|
| 13 |
|
| 14 |
from roles_list import roles
|
| 15 |
-
from openai import OpenAI
|
| 16 |
# Load the model from the specified directory
|
| 17 |
embed_store = {}
|
| 18 |
model = 'sentence-transformers/all-MiniLM-L12-v2'
|
| 19 |
sbert_model = AutoModel.from_pretrained(model)
|
| 20 |
sbert_tokenizer = AutoTokenizer.from_pretrained(model)
|
| 21 |
|
| 22 |
-
client = OpenAI(
|
| 23 |
-
# defaults to os.environ.get("OPENAI_API_KEY")
|
| 24 |
-
api_key="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",
|
| 25 |
-
)
|
| 26 |
-
|
| 27 |
|
| 28 |
for role in roles:
|
| 29 |
encoding = sbert_tokenizer(role, # the texts to be tokenized
|
|
@@ -65,30 +57,6 @@ def get_role_from_sbert(title):
|
|
| 65 |
return job_scores_str + f" \nExecution time: {str(execution_time)}"
|
| 66 |
|
| 67 |
|
| 68 |
-
def fuzzy_match(title):
|
| 69 |
-
"""
|
| 70 |
-
Find the best matches for a query from a list of choices using fuzzy matching.
|
| 71 |
-
|
| 72 |
-
Parameters:
|
| 73 |
-
- query: The search string.
|
| 74 |
-
- choices: A list of strings to search through.
|
| 75 |
-
- limit: The maximum number of matches to return.
|
| 76 |
-
|
| 77 |
-
Returns:
|
| 78 |
-
A list of tuples with the match and its score. Higher score means closer match.
|
| 79 |
-
"""
|
| 80 |
-
matches = process.extract(title, roles, limit=3)
|
| 81 |
-
return matches
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
def fuzzy_match_sbert(title):
|
| 85 |
-
matches = fuzzy_match(title)
|
| 86 |
-
sbert_results = get_role_from_sbert(title)
|
| 87 |
-
|
| 88 |
-
new_list = [matches, sbert_results]
|
| 89 |
-
return new_list
|
| 90 |
-
|
| 91 |
-
|
| 92 |
demo = gr.Interface(fn=get_role_from_sbert,
|
| 93 |
inputs=gr.Textbox(label="Job Title"),
|
| 94 |
outputs=gr.Textbox(label="Role"),
|
|
|
|
| 4 |
|
| 5 |
import gradio as gr
|
| 6 |
from transformers import AutoTokenizer, AutoModel
|
|
|
|
| 7 |
# pytorch library
|
| 8 |
import torch
|
| 9 |
import torch.nn.functional as f
|
| 10 |
|
|
|
|
| 11 |
|
| 12 |
from roles_list import roles
|
|
|
|
| 13 |
# Load the model from the specified directory
|
| 14 |
embed_store = {}
|
| 15 |
model = 'sentence-transformers/all-MiniLM-L12-v2'
|
| 16 |
sbert_model = AutoModel.from_pretrained(model)
|
| 17 |
sbert_tokenizer = AutoTokenizer.from_pretrained(model)
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
for role in roles:
|
| 21 |
encoding = sbert_tokenizer(role, # the texts to be tokenized
|
|
|
|
| 57 |
return job_scores_str + f" \nExecution time: {str(execution_time)}"
|
| 58 |
|
| 59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
demo = gr.Interface(fn=get_role_from_sbert,
|
| 61 |
inputs=gr.Textbox(label="Job Title"),
|
| 62 |
outputs=gr.Textbox(label="Role"),
|