Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import openai
|
3 |
+
import fitz # PyMuPDF
|
4 |
+
import torch
|
5 |
+
from transformers import pipeline
|
6 |
+
|
7 |
+
# Set OpenAI and Hugging Face API keys
|
8 |
+
openai.api_key = "your_openai_api_key"
|
9 |
+
|
10 |
+
# Initialize the Gemma model
|
11 |
+
gemma_pipe = pipeline(
|
12 |
+
"text-generation",
|
13 |
+
model="google/gemma-2-27b-it",
|
14 |
+
model_kwargs={"torch_dtype": torch.bfloat16},
|
15 |
+
device="cuda"
|
16 |
+
)
|
17 |
+
|
18 |
+
def extract_text_from_pdf(pdf_file):
|
19 |
+
document = fitz.open(pdf_file)
|
20 |
+
text = ""
|
21 |
+
for page_num in range(len(document)):
|
22 |
+
page = document.load_page(page_num)
|
23 |
+
text += page.get_text()
|
24 |
+
return text
|
25 |
+
|
26 |
+
def evaluate_with_gpt(pdf_file, job_description):
|
27 |
+
resume_text = extract_text_from_pdf(pdf_file)
|
28 |
+
|
29 |
+
prompt = f"""به عنوان یک تحلیلگر با تجربه سیستم ردیابی متقاضی (ATS)، نقش شما شامل ارزیابی رزومه در برابر شرح شغل است.
|
30 |
+
رزومه:{resume_text}
|
31 |
+
شرح شغل:{job_description}
|
32 |
+
"""
|
33 |
+
|
34 |
+
response = openai.ChatCompletion.create(
|
35 |
+
model="gpt-4o",
|
36 |
+
messages=[
|
37 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
38 |
+
{"role": "user", "content": prompt}
|
39 |
+
]
|
40 |
+
)
|
41 |
+
|
42 |
+
return response.choices[0].message['content']
|
43 |
+
|
44 |
+
def evaluate_with_gemma(pdf_file, job_description):
|
45 |
+
resume_text = extract_text_from_pdf(pdf_file)
|
46 |
+
|
47 |
+
prompt = f"Evaluate the following resume against the job description. Resume: {resume_text} Job Description: {job_description}"
|
48 |
+
|
49 |
+
outputs = gemma_pipe(prompt, max_new_tokens=256)
|
50 |
+
return outputs[0]["generated_text"].strip()
|
51 |
+
|
52 |
+
def evaluate_both_models(pdf_file, job_description):
|
53 |
+
gpt_result = evaluate_with_gpt(pdf_file, job_description)
|
54 |
+
gemma_result = evaluate_with_gemma(pdf_file, job_description)
|
55 |
+
return f"GPT-4o Result:\n{gpt_result}\n\nGemma Result:\n{gemma_result}"
|
56 |
+
|
57 |
+
iface = gr.Interface(
|
58 |
+
fn=lambda pdf, jd, model: evaluate_with_gpt(pdf, jd) if model == "GPT-4o" else evaluate_with_gemma(pdf, jd) if model == "Gemma" else evaluate_both_models(pdf, jd),
|
59 |
+
inputs=[
|
60 |
+
gr.File(label="Upload Resume PDF"),
|
61 |
+
gr.Textbox(lines=10, label="Job Description"),
|
62 |
+
gr.Radio(choices=["GPT-4o", "Gemma", "Both"], label="Choose Model")
|
63 |
+
],
|
64 |
+
outputs="text",
|
65 |
+
title="Resume Evaluator"
|
66 |
+
)
|
67 |
+
|
68 |
+
iface.launch()
|