Spaces:
Runtime error
Runtime error
import os | |
os.environ["OPENAI_API_KEY"] = "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" | |
import openai | |
import os | |
import PyPDF2 | |
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer | |
from dotenv import load_dotenv, find_dotenv | |
_ = load_dotenv(find_dotenv()) | |
openai.api_key = os.getenv('OPENAI_API_KEY') | |
def get_completion(prompt, model="gpt-3.5-turbo", temperature=0, max_tokens=500): | |
messages = [{"role": "user", "content": prompt}] | |
response = openai.ChatCompletion.create( | |
model=model, | |
temperature=temperature, | |
max_tokens=max_tokens, | |
messages=messages, | |
) | |
return response.choices[0].message["content"] | |
def generate_prompt(text, format="text"): | |
prompt = f"""Play as an AI HR recruiter specialist and extract all the jobs as a list with : | |
1. Job Title | |
2. Location | |
3. Educations as list | |
4. Experiences as list | |
5. Skills and Competences as list | |
6. Functions and Tasks as list | |
7. Return the result in {format} format \ | |
here the text \ | |
``` {text}``` | |
""" | |
return prompt | |
import PyPDF2 | |
def read_pdf(file_path): | |
pdf_file = open(file_path, 'rb') | |
pdf_reader = PyPDF2.PdfReader(pdf_file) | |
text = "" | |
for page in pdf_reader.pages: | |
text += page.extract_text() | |
pdf_file.close() | |
return text | |
import PyPDF2 | |
def summarize(input): | |
text = read_pdf(input.name) | |
prompt = generate_prompt(text) | |
response = get_completion(prompt) | |
return response | |
import gradio as gr | |
gr.close_all() | |
demo = gr.Interface( | |
fn=summarize, | |
inputs=gr.components.File(label="Importez votre document en format PDF ici"), | |
outputs=gr.components.Textbox(label="Voici le résultat"), | |
title="Téléchargement de CV (version anglaise)", | |
description="Outil d’importation de CV") | |
demo.launch() | |
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
import gradio as gr | |
def colorize_text(text): | |
return "<span style='color:red;background-color:orange'>" + text + "</span>" "<span style='color:white;background-color:red'>" + "Experiences" + "</span>" | |
iface = gr.Interface(fn=colorize_text, inputs="text", outputs="html") | |
iface.launch() |