NER-ALIP / app.py
farwew's picture
Update app.py
30bc313 verified
raw
history blame contribute delete
911 Bytes
import os
import tarfile
import spacy
import gradio as gr
# Nama file dan lokasi ekstraksi
tar_file = "xx_cv_parsing_ner-0.0.1.tar.gz"
extract_path = "xx_cv_parsing_ner"
# Ekstrak jika belum diekstrak
if not os.path.exists(extract_path):
with tarfile.open(tar_file, "r:gz") as tar:
tar.extractall(path=extract_path)
# Load spaCy model
model_path = os.path.join(
extract_path, "xx_cv_parsing_ner-0.0.1", "xx_CV_Parsing_NER", "xx_CV_Parsing_NER-0.0.1"
)
nlp = spacy.load(model_path)
# Fungsi ekstraksi entitas
def extract_entities(text):
doc = nlp(text)
return [(ent.text, ent.label_) for ent in doc.ents]
# Gradio UI
demo = gr.Interface(
fn=extract_entities,
inputs=gr.Textbox(lines=15, label="Masukkan Teks CV"),
outputs=gr.Dataframe(headers=["Entity", "Label"], label="Hasil Ekstraksi"),
title="Ekstraksi Entitas CV"
)
if __name__ == "__main__":
demo.launch()