File size: 1,804 Bytes
091b77e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from transformers import pipeline, AutoModelForTokenClassification, AutoTokenizer
import sentencepiece
import streamlit as st
import pandas as pd

text_1 = "ddd"

text_2 = """ddd"""

st.title("Demo for Biomedical POS Tagging in French with DrBERT")
st.sidebar.write("Model : DrBERT-7GB base CAS corpus POS tagging")
st.sidebar.write("For details of model: 'https://huggingface.co/Dr-BERT/DrBERT-7GB'")

model_checkpoint = "Dr-BERT/DrBERT-7GB"
aggregation = "simple"

st.subheader("Select Text")
context_1 = st.text_area("Text #1", text_1, height=128)
context_2 = st.text_area("Text #2", text_2, height=128)
context_3 = st.text_area("New Text", value="", height=128)

context = st.radio("Select Text", ("Text #1", "Text #2", "New Text"))

if context == "Text #1":
    input_text = context_1
elif context == "Text #2":
    input_text = context_2
elif context == "New Text":
    input_text = context_3

@st.cache(allow_output_mutation=True)
def setModel(model_checkpoint, aggregation):
    model = AutoModelForTokenClassification.from_pretrained(model_checkpoint)
    tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
    return pipeline('token-classification', model=model, tokenizer=tokenizer, aggregation_strategy=aggregation)
        
Run_Button = st.button("Run", key=None)
if Run_Button == True:
    
    ner_pipeline = setModel(model_checkpoint, aggregation)
    output = ner_pipeline(input_text)

    df = pd.DataFrame.from_dict(output)

    if aggregation != "none":
        df.rename(index=str,columns={'entity_group':'POS Tag'},inplace=True)
    else:
        df.rename(index=str,columns={'entity_group':'POS Tag'},inplace=True)
    
    cols_to_keep = ['word','POS Tag','score','start','end']
    df_final = df[cols_to_keep]
    
    st.subheader("POS Tags")
    st.dataframe(df_final)