farwew commited on
Commit
040033f
·
verified ·
1 Parent(s): 9220978

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import tarfile
3
+ import gdown
4
+ import spacy
5
+ import gradio as gr
6
+
7
+ # URL dan path file model
8
+ drive_url = "https://drive.google.com/uc?id=1bOJ3fN9UeOKVam8SHYxDUDpb7ihNph1L"
9
+ tar_file = "xx_cv_parsing_ner.tar.gz"
10
+ extract_path = "xx_cv_parsing_ner"
11
+
12
+ # Cek apakah sudah diekstrak
13
+ if not os.path.exists(extract_path):
14
+ print("Mengunduh model...")
15
+ gdown.download(drive_url, tar_file, quiet=False)
16
+
17
+ print("Mengekstrak model...")
18
+ with tarfile.open(tar_file, "r:gz") as tar:
19
+ tar.extractall(path=extract_path)
20
+
21
+ # Load spaCy model
22
+ model_path = os.path.join(
23
+ extract_path, "xx_cv_parsing_ner-0.0.1", "xx_CV_Parsing_NER", "xx_CV_Parsing_NER-0.0.1"
24
+ )
25
+ nlp = spacy.load(model_path)
26
+
27
+ # Fungsi ekstraksi entitas
28
+ def extract_entities(text):
29
+ doc = nlp(text)
30
+ return [(ent.text, ent.label_) for ent in doc.ents]
31
+
32
+ # Gradio UI
33
+ demo = gr.Interface(
34
+ fn=extract_entities,
35
+ inputs=gr.Textbox(lines=15, label="Masukkan Teks CV"),
36
+ outputs=gr.Dataframe(headers=["Entity", "Label"], label="Hasil Ekstraksi"),
37
+ title="Ekstraksi Entitas CV",
38
+ )
39
+
40
+ # Jalankan
41
+ if __name__ == "__main__":
42
+ demo.launch()