devopsmarc commited on
Commit
3058a65
1 Parent(s): cc56459

Initial Commit

Browse files
Files changed (2) hide show
  1. app.py +74 -0
  2. requirement.txt +7 -0
app.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ os.environ["OPENAI_API_KEY"] = "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"
3
+
4
+ import openai
5
+ import os
6
+ import PyPDF2
7
+ from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
8
+ from dotenv import load_dotenv, find_dotenv
9
+
10
+ _ = load_dotenv(find_dotenv())
11
+
12
+ openai.api_key = os.getenv('OPENAI_API_KEY')
13
+
14
+ def get_completion(prompt, model="gpt-3.5-turbo", temperature=0, max_tokens=500):
15
+ messages = [{"role": "user", "content": prompt}]
16
+
17
+ response = openai.ChatCompletion.create(
18
+ model=model,
19
+ temperature=temperature,
20
+ max_tokens=max_tokens,
21
+ messages=messages,
22
+ )
23
+
24
+ return response.choices[0].message["content"]
25
+
26
+ def generate_prompt(text, format="text"):
27
+ prompt = f"""Play as an AI HR recruiter specialist and extract all the jobs as a list with :
28
+ 1. Job Title
29
+ 2. Location
30
+ 3. Educations as list
31
+ 4. Experiences as list
32
+ 5. Skills and Competences as list
33
+ 6. Functions and Tasks as list
34
+ 7. Return the result in {format} format \
35
+ here the text \
36
+ ``` {text}```
37
+
38
+
39
+ """
40
+ return prompt
41
+
42
+ import PyPDF2
43
+
44
+ def read_pdf(file_path):
45
+ pdf_file = open(file_path, 'rb')
46
+ pdf_reader = PyPDF2.PdfReader(pdf_file)
47
+ text = ""
48
+ for page in pdf_reader.pages:
49
+ text += page.extract_text()
50
+ pdf_file.close()
51
+ return text
52
+
53
+ import PyPDF2
54
+ def summarize(input):
55
+ text = read_pdf(input.name)
56
+ prompt = generate_prompt(text)
57
+ response = get_completion(prompt)
58
+ return response
59
+
60
+ import gradio as gr
61
+ gr.close_all()
62
+ demo = gr.Interface(fn=summarize, inputs="file", outputs="text",title="Experiences And Skills Extraction From PDF file with gpt-3.5-turbo")
63
+ demo.launch()
64
+
65
+ #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
66
+ #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
67
+
68
+ import gradio as gr
69
+
70
+ def colorize_text(text):
71
+ return "<span style='color:red;background-color:orange'>" + text + "</span>" "<span style='color:white;background-color:red'>" + "Experiences" + "</span>"
72
+
73
+ iface = gr.Interface(fn=colorize_text, inputs="text", outputs="html")
74
+ iface.launch()
requirement.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ openai==0.27.0
2
+ transformers==4.31.0
3
+ sentencepiece==0.1.99
4
+ PyPDF2==3.0.1
5
+ python-dotenv==1.0.0
6
+ gradio==3.39.0
7
+ torch==2.0.1