Spaces:
Running
Running
Update app.py
#13
by
edwin25
- opened
app.py
CHANGED
@@ -1,11 +1,47 @@
|
|
1 |
import gradio as gr
|
2 |
import fitz # PyMuPDF
|
3 |
-
|
|
|
|
|
4 |
|
5 |
def extract_text_from_pdf(pdf_file):
|
6 |
-
"""
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
def evaluate_resume(resume_text, job_description, model):
|
11 |
"""Evaluates the resume text using the specified model."""
|
@@ -23,24 +59,72 @@ def evaluate_resume(resume_text, job_description, model):
|
|
23 |
# If "All" is selected, evaluate with all models and return combined results.
|
24 |
return evaluate_all_models(resume_text, job_description)
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
def evaluate_multiple_resumes(resume_files, job_description, model):
|
27 |
"""Evaluates multiple resumes and returns the results."""
|
28 |
results = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
for resume_file in resume_files:
|
30 |
title = resume_file.name
|
31 |
resume_text = extract_text_from_pdf(resume_file)
|
32 |
result = evaluate_resume(resume_text, job_description, model)
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
iface = gr.Interface(
|
37 |
fn=evaluate_multiple_resumes,
|
38 |
inputs=[
|
39 |
-
gr.File(type="
|
40 |
gr.Textbox(lines=10, label="Job Description"),
|
41 |
gr.Radio(choices=["GPT-4o", "Gemma", "Bloom", "jabir", "llama", "All"], label="Choose Model")
|
42 |
],
|
43 |
-
outputs="
|
44 |
title="Multiple Resume Evaluator"
|
45 |
)
|
46 |
|
|
|
1 |
import gradio as gr
|
2 |
import fitz # PyMuPDF
|
3 |
+
import pandas as pd
|
4 |
+
import requests
|
5 |
+
from io import BytesIO
|
6 |
|
7 |
def extract_text_from_pdf(pdf_file):
|
8 |
+
"""Extract text from PDF file."""
|
9 |
+
doc = fitz.open(pdf_file)
|
10 |
+
text = ""
|
11 |
+
for page in doc:
|
12 |
+
text += page.get_text()
|
13 |
+
return text
|
14 |
+
|
15 |
+
def evaluate_with_jabir(resume_text, job_description):
|
16 |
+
prompt = f"""بر اساس این معیار های اندازه گیری که در زیر عنوان شده:
|
17 |
+
وضعیت خدمت سربازی
|
18 |
+
، سن،
|
19 |
+
محل سکونت،
|
20 |
+
محدوده حقوق پرداختی
|
21 |
+
، میزان سابقه کار مدیریتی،
|
22 |
+
میزان سابقه کار مرتبط با گروه شغلی مشابه
|
23 |
+
، میزان سابقه کار در صنعت،
|
24 |
+
میزان تحصیلات،
|
25 |
+
مهارت زبان،
|
26 |
+
مهارت های نرم افزاری
|
27 |
+
بیا درصد تطابق رزومه فرد با شرح شغلی را محاسبه کن و برای هر معیار اندازه گیری درصد تطابق را محاسبه کن و نهایتا یک درصد کلی برای تطابق رزومه فرد با شرح شغلی بده
|
28 |
+
میخوام خیلی دقیق محاسبه کنی و این درصد ها را در خروجی به صورت جیسون برگردان
|
29 |
+
روی مهارت ها بیشتر دقت کن و تک به تک برسی کن
|
30 |
+
شرح شغل: {job_description}
|
31 |
+
رزومه: {resume_text}"""
|
32 |
+
|
33 |
+
base_url = "https://api.jabirproject.org/generate"
|
34 |
+
headers = {"apikey": "7471142a-deb4-4a70-8ee3-6603e21bcc1d"}
|
35 |
+
data = {
|
36 |
+
"messages": [{"role": "user", "content": prompt}]
|
37 |
+
}
|
38 |
+
|
39 |
+
response = requests.post(base_url, headers=headers, json=data)
|
40 |
+
|
41 |
+
if response.ok:
|
42 |
+
return response.json()
|
43 |
+
else:
|
44 |
+
return f"Error: {response.status_code}, {response.text}"
|
45 |
|
46 |
def evaluate_resume(resume_text, job_description, model):
|
47 |
"""Evaluates the resume text using the specified model."""
|
|
|
59 |
# If "All" is selected, evaluate with all models and return combined results.
|
60 |
return evaluate_all_models(resume_text, job_description)
|
61 |
|
62 |
+
def create_excel_output(results, job_description_features):
|
63 |
+
"""Creates an Excel file from the results."""
|
64 |
+
# Create a DataFrame from the results
|
65 |
+
df = pd.DataFrame(results)
|
66 |
+
|
67 |
+
# Insert job description features in the second row
|
68 |
+
job_desc_row = pd.Series(job_description_features)
|
69 |
+
df.loc[-1] = job_desc_row # adding a row
|
70 |
+
df.index = df.index + 1 # shifting index
|
71 |
+
df = df.sort_index() # sorting by index to place it at the second row
|
72 |
+
|
73 |
+
# Save to Excel
|
74 |
+
output = BytesIO()
|
75 |
+
with pd.ExcelWriter(output, engine='xlsxwriter') as writer:
|
76 |
+
df.to_excel(writer, index=False)
|
77 |
+
output.seek(0)
|
78 |
+
return output
|
79 |
+
|
80 |
def evaluate_multiple_resumes(resume_files, job_description, model):
|
81 |
"""Evaluates multiple resumes and returns the results."""
|
82 |
results = []
|
83 |
+
job_description_features = {
|
84 |
+
"وضعیت خدمت سربازی": "",
|
85 |
+
"سن": "",
|
86 |
+
"محل سکونت": "",
|
87 |
+
"محدوده حقوق پرداختی": "",
|
88 |
+
"میزان سابقه کار مدیریتی": "",
|
89 |
+
"میزان سابقه کار مرتبط با گروه شغلی مشابه": "",
|
90 |
+
"میزان سابقه کار در صنعت": "",
|
91 |
+
"میزان تحصیلات": "",
|
92 |
+
"مهارت زبان": "",
|
93 |
+
"مهارت های نرم افزاری": ""
|
94 |
+
}
|
95 |
+
|
96 |
for resume_file in resume_files:
|
97 |
title = resume_file.name
|
98 |
resume_text = extract_text_from_pdf(resume_file)
|
99 |
result = evaluate_resume(resume_text, job_description, model)
|
100 |
+
|
101 |
+
# Adding the title of the resume and the total match percentage
|
102 |
+
resume_data = {
|
103 |
+
"رزومه": title,
|
104 |
+
"درصد تطابق کلی": result.get("overall_match_percentage", 0)
|
105 |
+
}
|
106 |
+
|
107 |
+
# Adding each feature match to the resume data
|
108 |
+
for feature, match in result.get("feature_matches", {}).items():
|
109 |
+
resume_data[feature] = match
|
110 |
+
|
111 |
+
# Adding skills as a list in one column
|
112 |
+
resume_data["مهارت ها"] = ", ".join(result.get("skills", []))
|
113 |
+
|
114 |
+
results.append(resume_data)
|
115 |
+
|
116 |
+
# Create Excel output
|
117 |
+
output = create_excel_output(results, job_description_features)
|
118 |
+
return output
|
119 |
|
120 |
iface = gr.Interface(
|
121 |
fn=evaluate_multiple_resumes,
|
122 |
inputs=[
|
123 |
+
gr.File(type="file", label="Upload Resumes PDF", file_count="multiple"),
|
124 |
gr.Textbox(lines=10, label="Job Description"),
|
125 |
gr.Radio(choices=["GPT-4o", "Gemma", "Bloom", "jabir", "llama", "All"], label="Choose Model")
|
126 |
],
|
127 |
+
outputs=gr.File(label="Download Excel File"),
|
128 |
title="Multiple Resume Evaluator"
|
129 |
)
|
130 |
|