File size: 3,149 Bytes
c68a703
1c7c1d3
f2d3ac9
1d086f7
07972f6
1c7c1d3
07972f6
1c7c1d3
 
 
f2d3ac9
07972f6
 
 
d35f003
9a1694c
 
 
 
f2d3ac9
 
 
 
 
 
9a1694c
 
5ce7b7b
f2d3ac9
07972f6
f2d3ac9
 
07972f6
da7bb3f
7a9bfed
1d086f7
07972f6
1c7c1d3
050a351
d2c3acc
 
 
 
f2d3ac9
d2c3acc
f2d3ac9
d2c3acc
f2d3ac9
d2c3acc
 
f2d3ac9
 
 
 
 
d2c3acc
 
f2d3ac9
 
 
 
 
d2c3acc
f2d3ac9
 
 
 
d2c3acc
f2d3ac9
d2c3acc
f2d3ac9
 
 
d2c3acc
f2d3ac9
 
 
 
d2c3acc
f2d3ac9
 
 
 
 
 
 
 
8bac8c2
f2d3ac9
 
 
1c7c1d3
07972f6
 
 
 
 
4235c40
 
 
 
e2a3cdc
 
 
 
 
4235c40
 
07972f6
8bac8c2
1c7c1d3
07972f6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import gradio as gr
import os
import io
import PyPDF2
#from langchain.llms import OpenAIChat
from langchain_openai import ChatOpenAI

from langchain.chains import LLMChain
from langchain.memory import ConversationBufferMemory
from langchain import PromptTemplate


# Updated imports for Gradio components
from gradio.components import File, Textbox

def extract_text_from_pdf_binary(pdf_binary):
    text = ""
    pdf_data = io.BytesIO(pdf_binary)
    reader = PyPDF2.PdfReader(pdf_data)
    num_pages = len(reader.pages)

    for page in range(num_pages):
        current_page = reader.pages[page]
        page_text = current_page.extract_text()
        if page_text:  # Check if page_text is not None or empty
            text += page_text
    return text

def format_resume_to_yaml(api_key, file_content):
    # Set the API key for OpenAI
    os.environ['OPENAI_API_KEY'] = api_key

    # Check if the file content is not empty
    if not file_content:
        raise ValueError("The uploaded file is empty.")

    # Extract text from the uploaded PDF binary
    resume_text = extract_text_from_pdf_binary(file_content)

    template = """Format the provided resume to this YAML template:
    ---
    name: ''
    phoneNumbers:
    - ''
    websites:
    - ''
    emails:
    - ''
    dateOfBirth: ''
    addresses:
    - street: ''
      city: ''
      state: ''
      zip: ''
      country: ''
    summary: ''
    education:
    - school: ''
      degree: ''
      fieldOfStudy: ''
      startDate: ''
      endDate: ''
    workExperience:
    - company: ''
      position: ''
      startDate: ''
      endDate: ''
    skills:
    - name: ''
    certifications:
    - name: ''
    {chat_history}
    {human_input}"""

    prompt = PromptTemplate(
        input_variables=["chat_history", "human_input"],
        template=template
    )

    memory = ConversationBufferMemory(memory_key="chat_history")

    llm_chain = LLMChain(
        llm=ChatOpenAI(model="gpt-3.5-turbo"),
        prompt=prompt,
        verbose=True,
        memory=memory,
    )

    res = llm_chain.predict(human_input=resume_text)
    return res

def main():
    input_api_key = Textbox(label="Enter your OpenAI API Key")
    input_pdf_file = File(label="Upload your PDF resume", type="binary")
    output_yaml = Textbox(label="Formatted Resume in YAML")

    iface = gr.Interface(
        fn=format_resume_to_yaml,
        inputs=[input_api_key, input_pdf_file],
        outputs=output_yaml,
        title="Resume to YAML Formatter",
        description="""This tool allows you to upload a PDF resume and formats it into a YAML template, 
        suitable for modern Applicant Tracking Systems. Please provide your OpenAI API key (you can obtain one 
        from [OpenAI](https://platform.openai.com/api-keys)) and upload your resume as a PDF. The backend is powered by Python and 
        uses the LangChain πŸ¦œοΈπŸ”— library for processing. For more information and updates, visit my [GitHub](https://github.com/barghavanii/Resume-analytics-).""",
        allow_flagging="never",
    )

    iface.launch(debug=True, share=True)

if __name__ == "__main__":
    main()