-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcv.py
More file actions
69 lines (53 loc) · 1.82 KB
/
cv.py
File metadata and controls
69 lines (53 loc) · 1.82 KB
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
import streamlit as st
from PyPDF2 import PdfReader, PdfWriter
from io import BytesIO
import dotenv
dotenv.load_dotenv(".env")
def extract_text_from_pdf(file):
from tempfile import NamedTemporaryFile
with NamedTemporaryFile(dir='.', suffix='.pdf') as f:
f.write(file.getbuffer())
text = ""
with open(f.name, "rb") as f:
reader = PdfReader(f)
for page in reader.pages:
text += page.extract_text()
return text
def create_pdf_from_text(text):
writer = PdfWriter()
writer.add_page()
writer.pages[0].append_text(text)
output_pdf = BytesIO()
writer.write(output_pdf)
return output_pdf.getvalue()
def call_open_ai(prompt, model="gpt-3.5-turbo"):
from openai import OpenAI
client = OpenAI()
stream = client.chat.completions.create(
model=model,
messages=[{"role": "user", "content": prompt}],
stream=False,
)
return stream.choices[0].message.content
def main():
st.title("CV optimater")
uploaded_file = st.file_uploader("Upload your current CV", type="pdf")
position = st.text_area("The poistion copied details:")
prompt = st.text_area("The prompt",value="""
Here is a user CV:
{cv_text}
and there a position he or she is intreasted in:
{position}
optimize the cv to the position, don't invent details.
- provide the response in markdown format.
- don't state the position company name in the response
""")
if st.button("Optimize my CV!"):
cv_text = extract_text_from_pdf(uploaded_file)
if cv_text.strip():
word_count = call_open_ai(prompt.format(position=position,cv_text=cv_text))
st.write(word_count)
else:
st.warning("Error when reading the CV")
if __name__ == "__main__":
main()