glitch0011 commited on
Commit
791e590
1 Parent(s): 26b4292

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load the pre-trained NER model
5
+ model = pipeline("ner", model="/home/user/app/mendobert/", tokenizer="indolem/indobert-base-uncased")
6
+ # basemodel = pipeline("ner", model="/home/user/app/base-model/", tokenizer="indolem/indobert-base-uncased")
7
+
8
+ def text_analysis(text):
9
+ doc = model(text)
10
+ html = displacy.render(doc, style="dep", page=True)
11
+ html = (
12
+ "<div style='max-width:100%; max-height:360px; overflow:auto'>"
13
+ + html
14
+ + "</div>"
15
+ )
16
+ pos_count = {
17
+ "char_count": len(text),
18
+ "token_count": 0,
19
+ }
20
+ pos_tokens = []
21
+
22
+ for token in doc:
23
+ pos_tokens.extend([(token.text, token.pos_), (" ", None)])
24
+
25
+ return pos_tokens, pos_count, html
26
+
27
+ demo = gr.Interface(
28
+ text_analysis,
29
+ gr.Textbox(placeholder="Enter sentence here..."),
30
+ ["highlight", "json", "html"],
31
+ examples=[
32
+ ["Aspartylglucosaminuria (AGU) adalah gangguan metabolisme glikoprotein langka."],
33
+ ["Mutasi germ - line dari gen BRCA1 membuat wanita cenderung mengalami kanker payudara dini dengan mengorbankan fungsi presumtif gen sebagai penekan tumor."],
34
+ ],
35
+ )
36
+
37
+ demo.launch()