# import spacy
# import gradio as gr
# from spacy import displacy
# from pdfminer.high_level import extract_text
# nlp = spacy.load("en_cv_info_extr")
# colors = {}
# for label in nlp.get_pipe('ner').labels:
# colors[label] = "linear-gradient(90deg, #aa9cfc, #fc9ce7)"
# options = {"ents": list(nlp.get_pipe('ner').labels), "colors": colors}
# def resume_ner(file):
# resume = extract_text(file.name)
# doc = nlp(resume)
# html = displacy.render(doc, style="ent", page=True, options=options)
# html = (
# "
"
# + html
# + "
"
# )
# return html
# demo = gr.Interface(
# resume_ner,
# gr.File(file_types=[".pdf"]),
# ["html"],
# )
# demo.launch()
import spacy
import gradio as gr
from spacy import displacy
from pdfminer.high_level import extract_text
# Load the custom NER model
nlp = spacy.load("en_cv_info_extr")
# Define the options for displacy.render with no colors
options = {"ents": list(nlp.get_pipe('ner').labels), "colors": {}}
def resume_ner(file):
# Extract text from the PDF
resume = extract_text(file.name)
# Process the text with the NLP model
doc = nlp(resume)
# Render the entities in plain HTML (no colors)
html = displacy.render(doc, style="ent", page=True, options=options)
# Wrap the HTML in a div for better display
html = (
""
+ html
+ "
"
)
return html
# Create the Gradio interface
demo = gr.Interface(
resume_ner,
gr.File(file_types=[".pdf"]),
["html"],
)
# Launch the Gradio app
demo.launch()