Spaces:
Sleeping
Sleeping
Commit
·
1189adc
1
Parent(s):
b547b95
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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(
|
| 63 |
+
fn=summarize,
|
| 64 |
+
inputs=gr.components.File(label="Importez votre document en format PDF ici"),
|
| 65 |
+
outputs=gr.components.Textbox(label="Voici le résultat"),
|
| 66 |
+
title="Téléchargement de CV\n(version anglaise)",
|
| 67 |
+
description="Outil d’importation de CV")
|
| 68 |
+
demo.launch()
|
| 69 |
+
|
| 70 |
+
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
| 71 |
+
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
| 72 |
+
|
| 73 |
+
import gradio as gr
|
| 74 |
+
|
| 75 |
+
def colorize_text(text):
|
| 76 |
+
return "<span style='color:red;background-color:orange'>" + text + "</span>" "<span style='color:white;background-color:red'>" + "Experiences" + "</span>"
|
| 77 |
+
|
| 78 |
+
iface = gr.Interface(fn=colorize_text, inputs="text", outputs="html")
|
| 79 |
+
iface.launch()
|