Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,60 @@
|
|
1 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
2 |
import os
|
3 |
import gradio as gr
|
|
|
|
|
4 |
|
5 |
-
#
|
6 |
hf_token = os.environ.get("hf_space_token")
|
7 |
-
|
8 |
model_name = "google/gemma-3-1b-it"
|
9 |
tokenizer = AutoTokenizer.from_pretrained(model_name, token=hf_token)
|
10 |
model = AutoModelForCausalLM.from_pretrained(model_name, token=hf_token)
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
-
iface.launch()
|
|
|
1 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
2 |
import os
|
3 |
import gradio as gr
|
4 |
+
import PyPDF2
|
5 |
+
import docx2txt
|
6 |
|
7 |
+
# Load token and model
|
8 |
hf_token = os.environ.get("hf_space_token")
|
|
|
9 |
model_name = "google/gemma-3-1b-it"
|
10 |
tokenizer = AutoTokenizer.from_pretrained(model_name, token=hf_token)
|
11 |
model = AutoModelForCausalLM.from_pretrained(model_name, token=hf_token)
|
12 |
|
13 |
+
# Resume text extraction
|
14 |
+
def extract_text_from_resume(file):
|
15 |
+
if file is None:
|
16 |
+
return "No file uploaded."
|
17 |
+
ext = file.name.split('.')[-1].lower()
|
18 |
+
if ext == "pdf":
|
19 |
+
reader = PyPDF2.PdfReader(file)
|
20 |
+
return "\n".join([page.extract_text() for page in reader.pages if page.extract_text()])
|
21 |
+
elif ext == "docx":
|
22 |
+
return docx2txt.process(file.name)
|
23 |
+
else:
|
24 |
+
return "Unsupported file format."
|
25 |
+
|
26 |
+
# Function to generate LLM response
|
27 |
+
def analyze_resume(job_description, resume_file, analyze_with_jd):
|
28 |
+
resume_text = extract_text_from_resume(resume_file)
|
29 |
+
if not resume_text.strip():
|
30 |
+
return "Unable to extract resume content."
|
31 |
+
|
32 |
+
if analyze_with_jd and job_description.strip():
|
33 |
+
prompt = (
|
34 |
+
f"Compare the following resume with this job description:\n\n"
|
35 |
+
f"Job Description:\n{job_description}\n\n"
|
36 |
+
f"Resume:\n{resume_text}\n\n"
|
37 |
+
f"Give a short summary of how well this resume matches the job."
|
38 |
+
)
|
39 |
+
else:
|
40 |
+
prompt = f"Summarize the following resume:\n\n{resume_text}"
|
41 |
+
|
42 |
+
inputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=2048)
|
43 |
+
outputs = model.generate(**inputs, max_new_tokens=200, do_sample=True, temperature=0.7)
|
44 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
45 |
|
46 |
+
# Build Gradio UI
|
47 |
+
with gr.Blocks() as demo:
|
48 |
+
with gr.Row():
|
49 |
+
with gr.Column():
|
50 |
+
analyze_checkbox = gr.Checkbox(label="Analyze with Job Description", value=True)
|
51 |
+
job_desc = gr.Textbox(label="Job Description", lines=8, placeholder="Paste job description here...")
|
52 |
+
resume_file = gr.File(label="Upload Resume (PDF or DOCX)", file_types=[".pdf", ".docx"])
|
53 |
+
with gr.Column():
|
54 |
+
parsed_output = gr.Textbox(label="Gemma Analysis Output", lines=20)
|
55 |
+
|
56 |
+
resume_file.change(fn=analyze_resume, inputs=[job_desc, resume_file, analyze_checkbox], outputs=parsed_output)
|
57 |
+
job_desc.change(fn=analyze_resume, inputs=[job_desc, resume_file, analyze_checkbox], outputs=parsed_output)
|
58 |
+
|
59 |
+
demo.launch()
|
60 |
|
|