Spaces:
Sleeping
Sleeping
Commit
·
f8af8bb
1
Parent(s):
c601280
Fixed app v2
Browse files- app.py +12 -27
- requirements.txt +1 -0
app.py
CHANGED
@@ -1,32 +1,26 @@
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
-
from llama_cpp import Llama
|
3 |
from transformers import pipeline
|
4 |
import json
|
5 |
|
6 |
-
# Load
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
filename="smollm2-360m-instruct-q8_0.gguf" # Replace with the correct path to your GGUF file
|
11 |
-
)
|
12 |
-
except Exception as e:
|
13 |
-
raise RuntimeError(f"Failed to load model: {e}")
|
14 |
|
15 |
-
#
|
16 |
summarizer = pipeline("summarization")
|
17 |
|
18 |
-
# Summarize text to fit within token limits
|
19 |
def summarize_text(text, max_length=100):
|
20 |
-
# Use the summarizer to condense the text
|
21 |
summary = summarizer(text, max_length=max_length, min_length=25, do_sample=False)
|
22 |
return summary[0]["summary_text"]
|
23 |
|
24 |
-
# Function to match CV to job descriptions with debug information
|
25 |
def match_cv_to_jobs(cv_text, job_descriptions):
|
26 |
debug_info = "Debug Info:\n"
|
27 |
results = []
|
28 |
|
29 |
-
# Summarize
|
30 |
summarized_cv = summarize_text(cv_text, max_length=400)
|
31 |
debug_info += f"Summarized CV Text: {summarized_cv}\n"
|
32 |
|
@@ -35,7 +29,7 @@ def match_cv_to_jobs(cv_text, job_descriptions):
|
|
35 |
summarized_description = summarize_text(description, max_length=100)
|
36 |
debug_info += f"\nSummarized Job Description: {summarized_description}\n"
|
37 |
|
38 |
-
# Create a prompt to compare the summarized CV with each
|
39 |
prompt = (
|
40 |
f"Compare the following job description with this resume. Job Description: {summarized_description}. "
|
41 |
f"Resume: {summarized_cv}. Provide a match score and a brief analysis."
|
@@ -43,21 +37,12 @@ def match_cv_to_jobs(cv_text, job_descriptions):
|
|
43 |
debug_info += f"\nGenerated Prompt: {prompt}\n"
|
44 |
|
45 |
# Generate response from the model
|
|
|
46 |
try:
|
47 |
-
|
48 |
-
|
49 |
-
{
|
50 |
-
"role": "user",
|
51 |
-
"content": prompt
|
52 |
-
}
|
53 |
-
]
|
54 |
-
)
|
55 |
-
|
56 |
-
# Extract the analysis text
|
57 |
-
response_content = response["choices"][0]["message"]["content"]
|
58 |
debug_info += f"Model Response: {response_content}\n"
|
59 |
|
60 |
-
# Attempt to parse as JSON; if not JSON, use the raw text
|
61 |
try:
|
62 |
response_data = json.loads(response_content)
|
63 |
results.append(response_data)
|
|
|
1 |
+
from transformers import AutoTokenizer
|
2 |
+
from optimum.intel.openvino import OVModelForCausalLM
|
3 |
import gradio as gr
|
|
|
4 |
from transformers import pipeline
|
5 |
import json
|
6 |
|
7 |
+
# Load OpenVINO GPT-J model
|
8 |
+
model_id = "OpenVINO/gpt-j-6b-int4-ov"
|
9 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
10 |
+
model = OVModelForCausalLM.from_pretrained(model_id)
|
|
|
|
|
|
|
|
|
11 |
|
12 |
+
# Summarization pipeline
|
13 |
summarizer = pipeline("summarization")
|
14 |
|
|
|
15 |
def summarize_text(text, max_length=100):
|
|
|
16 |
summary = summarizer(text, max_length=max_length, min_length=25, do_sample=False)
|
17 |
return summary[0]["summary_text"]
|
18 |
|
|
|
19 |
def match_cv_to_jobs(cv_text, job_descriptions):
|
20 |
debug_info = "Debug Info:\n"
|
21 |
results = []
|
22 |
|
23 |
+
# Summarize the CV text
|
24 |
summarized_cv = summarize_text(cv_text, max_length=400)
|
25 |
debug_info += f"Summarized CV Text: {summarized_cv}\n"
|
26 |
|
|
|
29 |
summarized_description = summarize_text(description, max_length=100)
|
30 |
debug_info += f"\nSummarized Job Description: {summarized_description}\n"
|
31 |
|
32 |
+
# Create a prompt to compare the summarized CV with each job description
|
33 |
prompt = (
|
34 |
f"Compare the following job description with this resume. Job Description: {summarized_description}. "
|
35 |
f"Resume: {summarized_cv}. Provide a match score and a brief analysis."
|
|
|
37 |
debug_info += f"\nGenerated Prompt: {prompt}\n"
|
38 |
|
39 |
# Generate response from the model
|
40 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
41 |
try:
|
42 |
+
outputs = model.generate(**inputs, max_length=200)
|
43 |
+
response_content = tokenizer.batch_decode(outputs, skip_special_tokens=True)[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
debug_info += f"Model Response: {response_content}\n"
|
45 |
|
|
|
46 |
try:
|
47 |
response_data = json.loads(response_content)
|
48 |
results.append(response_data)
|
requirements.txt
CHANGED
@@ -5,3 +5,4 @@ torch==2.0.0 # Specifying PyTorch 2.0
|
|
5 |
git+https://github.com/abetlen/llama-cpp-python.git
|
6 |
nest_asyncio
|
7 |
pydantic
|
|
|
|
5 |
git+https://github.com/abetlen/llama-cpp-python.git
|
6 |
nest_asyncio
|
7 |
pydantic
|
8 |
+
optimum
|