aakash0563 commited on
Commit
f0b1fb1
1 Parent(s): 5b0ab56

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +82 -0
app.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain.llms.huggingface_pipeline import HuggingFacePipeline
2
+ import torch
3
+ from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
4
+ from transformers import BitsAndBytesConfig
5
+ import pdfplumber
6
+ from langchain.prompts import PromptTemplate
7
+
8
+ nf4_config = BitsAndBytesConfig(
9
+ load_in_4bit=True,
10
+ bnb_4bit_quant_type="nf4",
11
+ bnb_4bit_use_double_quant=True,
12
+ bnb_4bit_compute_dtype=torch.bfloat16
13
+ )
14
+
15
+ model_id = "huggingFaceH4/zephyr-7b-alpha"
16
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
17
+ model = AutoModelForCausalLM.from_pretrained(
18
+ model_id,
19
+ quantization_config=nf4_config,
20
+ device_map="auto"
21
+ )
22
+
23
+ model.tie_weights()
24
+
25
+ pipe = pipeline("text-generation",
26
+ model=model,
27
+ tokenizer=tokenizer,
28
+ max_new_tokens= 512
29
+ )
30
+
31
+ llm = HuggingFacePipeline(pipeline=pipe)
32
+
33
+ ## LLM Response
34
+ def get_llm_response(input):
35
+ res = llm.predict(input)
36
+ return res
37
+
38
+ def input_pdf_text(uploaded_file):
39
+ with open(uploaded_file, 'rb') as f:
40
+ pdf = pdfplumber.open(f)
41
+ text = ""
42
+ for page in pdf.pages:
43
+ text += page.extract_text()
44
+ return text
45
+
46
+
47
+ def Get_Response(upload_pdf,jd):
48
+ text = input_pdf_text(upload_pdf)
49
+ prompt_template = PromptTemplate.from_template(
50
+ """
51
+ Hey Act Like a skilled or very experience ATS(Application Tracking System)
52
+ with a deep understanding of tech field, software engineering, data science,
53
+ data analyst and big data engineer. Your Task is to evaluate the resume based on the
54
+ given job description.
55
+ You must consider the job market is very competitive and you should provide
56
+ best assistance for the improving the resume. Assisn the percentage Matching
57
+ based on JD(Job Description) and the missing keywords with high accuracy
58
+ resume:{text}
59
+ description:{jd}
60
+
61
+ I want the response in one single tring having the structure
62
+ {{"JD Match":"%","MissingKeywords:[]","Profile Summary":""}}
63
+ """)
64
+ prompt = prompt_template.format(text=text,jd=jd)
65
+ response = llm.predict(prompt)
66
+ return response
67
+
68
+ # Define Gradio interface
69
+ interface = gr.Interface(
70
+ fn=Get_Response,
71
+ inputs=["file","text"],
72
+ # inputs=[
73
+ # gr.File("upload_pdf", label="Upload PDF"),
74
+ # gr.Textbox("jd", label="Job Description"),
75
+ # ],
76
+ outputs="text",
77
+ title="Get ATS-Style Resume Evaluation",
78
+ description="Upload a resume PDF and provide a job description to get an evaluation with JD match percentage, missing keywords, and profile summary.",
79
+ )
80
+
81
+ # Launch the Gradio application
82
+ interface.launch(debug=True, share=True)