Commit
·
7067897
1
Parent(s):
e9970fa
Initial commit
Browse files- test-job-app.py +55 -0
test-job-app.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
import torch
|
4 |
+
|
5 |
+
# Load the SmolLM model and tokenizer
|
6 |
+
model_name = "HuggingFaceTB/SmolLM2-135M-Instruct" # "HuggingFaceTB/SmolLM2-360m-Instruct"
|
7 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
9 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
10 |
+
model.to(device)
|
11 |
+
|
12 |
+
def smol_lm_process(job_description):
|
13 |
+
# System Prompt: "Extract key qualifications, skills, and requirements from this job description. Output as bullet points. Remove benefits/salary fluff."
|
14 |
+
prompt = f"""<|im_start|>system
|
15 |
+
Extract key qualifications, skills, and requirements from this job description. Output as bullet points. Remove benefits/salary fluff.<|im_end|>
|
16 |
+
<|im_start|>user
|
17 |
+
{job_description}<|im_end|>
|
18 |
+
<|im_start|>assistant
|
19 |
+
"""
|
20 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(device)
|
21 |
+
output = model.generate(**inputs, max_new_tokens=512)
|
22 |
+
response = tokenizer.decode(output[0], skip_special_tokens=False)
|
23 |
+
# Extract the assistant's response
|
24 |
+
start_idx = response.find("<|im_start|>assistant")
|
25 |
+
end_idx = response.find("<|im_end|>", start_idx)
|
26 |
+
response = response[start_idx + len("<|im_start|>assistant\n"):end_idx].strip()
|
27 |
+
return response
|
28 |
+
|
29 |
+
def process_job_description(company_name, company_url, job_description):
|
30 |
+
role_requirements = smol_lm_process(job_description)
|
31 |
+
return {
|
32 |
+
"Company Name": company_name,
|
33 |
+
"Company URL": company_url,
|
34 |
+
"Job Description": job_description,
|
35 |
+
"Role Requirements": role_requirements
|
36 |
+
}
|
37 |
+
|
38 |
+
# Create the Gradio app
|
39 |
+
demo = gr.Blocks()
|
40 |
+
|
41 |
+
with demo:
|
42 |
+
gr.Markdown("# Job Description Input")
|
43 |
+
company_name = gr.Textbox(label="Company Name")
|
44 |
+
company_url = gr.Textbox(label="Company URL")
|
45 |
+
job_description = gr.TextArea(label="Paste Job Description")
|
46 |
+
|
47 |
+
gr.Button("Submit").click(
|
48 |
+
process_job_description,
|
49 |
+
inputs=[company_name, company_url, job_description],
|
50 |
+
outputs=gr.JSON(label="Output")
|
51 |
+
)
|
52 |
+
|
53 |
+
if __name__ == "__main__":
|
54 |
+
demo.launch()
|
55 |
+
|