Spaces:
Sleeping
Sleeping
Commit
·
f65dc03
1
Parent(s):
e079d59
Fixed app v2
Browse files
app.py
CHANGED
@@ -11,47 +11,55 @@ try:
|
|
11 |
except Exception as e:
|
12 |
raise RuntimeError(f"Failed to load model: {e}")
|
13 |
|
14 |
-
# Function to match CV to job descriptions
|
15 |
def match_cv_to_jobs(cv_text, job_descriptions):
|
16 |
-
|
17 |
-
descriptions = job_descriptions.strip().split("\n")
|
18 |
results = []
|
19 |
|
20 |
-
|
21 |
-
#
|
22 |
-
|
23 |
-
f"Compare the following job description with this resume. Job Description: {description}. "
|
24 |
-
f"Resume: {cv_text}. Provide a match score and a brief analysis."
|
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 |
-
return results
|
51 |
|
52 |
# Gradio interface
|
53 |
with gr.Blocks() as demo:
|
54 |
-
gr.Markdown("# CV and Job Description Matcher")
|
55 |
|
56 |
# Input fields for CV and job descriptions
|
57 |
cv_text = gr.Textbox(label="CV Text", placeholder="Enter the CV text here", lines=10)
|
@@ -60,8 +68,9 @@ with gr.Blocks() as demo:
|
|
60 |
# Button and output area
|
61 |
match_button = gr.Button("Match CV to Job Descriptions")
|
62 |
output = gr.JSON(label="Match Results")
|
|
|
63 |
|
64 |
# Set button click to run the function
|
65 |
-
match_button.click(fn=match_cv_to_jobs, inputs=[cv_text, job_descriptions], outputs=output)
|
66 |
|
67 |
demo.launch()
|
|
|
11 |
except Exception as e:
|
12 |
raise RuntimeError(f"Failed to load model: {e}")
|
13 |
|
14 |
+
# Function to match CV to job descriptions with debug information
|
15 |
def match_cv_to_jobs(cv_text, job_descriptions):
|
16 |
+
debug_info = "Debug Info:\n"
|
|
|
17 |
results = []
|
18 |
|
19 |
+
try:
|
20 |
+
# Split job descriptions by line
|
21 |
+
descriptions = job_descriptions.strip().split("\n")
|
|
|
|
|
|
|
22 |
|
23 |
+
for description in descriptions:
|
24 |
+
# Create a prompt to compare the CV with each job description
|
25 |
+
prompt = (
|
26 |
+
f"Compare the following job description with this resume. Job Description: {description}. "
|
27 |
+
f"Resume: {cv_text}. Provide a match score and a brief analysis."
|
28 |
+
)
|
29 |
+
debug_info += f"\nGenerated Prompt: {prompt}\n"
|
30 |
+
|
31 |
+
# Generate response from the model
|
32 |
+
response = llm.create_chat_completion(
|
33 |
+
messages=[
|
34 |
+
{
|
35 |
+
"role": "user",
|
36 |
+
"content": prompt
|
37 |
+
}
|
38 |
+
]
|
39 |
+
)
|
40 |
+
|
41 |
+
# Extract the analysis text
|
42 |
+
response_content = response["choices"][0]["message"]["content"]
|
43 |
+
debug_info += f"Model Response: {response_content}\n"
|
44 |
+
|
45 |
+
# Attempt to parse as JSON; if not JSON, use the raw text
|
46 |
+
try:
|
47 |
+
response_data = json.loads(response_content)
|
48 |
+
results.append(response_data)
|
49 |
+
except json.JSONDecodeError:
|
50 |
+
results.append({
|
51 |
+
"Job Description": description,
|
52 |
+
"Analysis": response_content # Use raw response if JSON parsing fails
|
53 |
+
})
|
54 |
+
except Exception as e:
|
55 |
+
debug_info += f"Error: {str(e)}\n"
|
56 |
+
results.append({"Error": str(e)})
|
57 |
|
58 |
+
return results, debug_info
|
59 |
|
60 |
# Gradio interface
|
61 |
with gr.Blocks() as demo:
|
62 |
+
gr.Markdown("# CV and Job Description Matcher with Debugging")
|
63 |
|
64 |
# Input fields for CV and job descriptions
|
65 |
cv_text = gr.Textbox(label="CV Text", placeholder="Enter the CV text here", lines=10)
|
|
|
68 |
# Button and output area
|
69 |
match_button = gr.Button("Match CV to Job Descriptions")
|
70 |
output = gr.JSON(label="Match Results")
|
71 |
+
debug_output = gr.Textbox(label="Debug Info", lines=10) # Add a debug box to display debug info
|
72 |
|
73 |
# Set button click to run the function
|
74 |
+
match_button.click(fn=match_cv_to_jobs, inputs=[cv_text, job_descriptions], outputs=[output, debug_output])
|
75 |
|
76 |
demo.launch()
|