File size: 10,239 Bytes
e81e0c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
import streamlit as st
import pandas as pd
import streamlit.components.v1 as components
import textwrap as tw

#st.set_page_config(  initial_sidebar_state="expanded", margin_top = 20, margin_left = 20, margin_right = 10, margin_bottom=50, footer_text = "Creative Commons ... " )
st.set_page_config(page_title='Portparser', layout="wide")
##9bc2d1,#9bc2d1,#2f76a3
page_bg_img = f"""

<style>

[data-testid="stAppViewContainer"] > .main {{

background: linear-gradient(180deg, #88bbcf,#f1f1f1,#f1f1f1,#f1f1f1); /**#ccebff 10%, #f1f1f1 90%  #0088be);

padding-left:4rem;

padding-right:4rem;

background-image: url("img/nilc.png");

background-repeat: repeat;

background-position: center center;

background-attachment: local;

/**#f1f1f1/** #008fb3/**#accad2;/**#b3b3ff;**/

/**background-image: url("https://i.postimg.cc/4xgNnkfX/Untitled-design.png");

background-position: center center;

background-repeat: no-repeat;

background-attachment: local;**/

}}

[data-testid="stForm"] {{

background-color: #9bc2d1;/**#7ebac9;/**#0086b3;**/

}}

.appview-container .main .block-container {{

    padding-top: 1rem;

    padding-bottom: 3rem;

    }}

h1 {{

    color:#003d66;/**#143350**/;

    padding-left:1rem;

    padding-right:1rem;

}}

[class="css-1n543e5 e1ewe7hr5"] {{

    background-color: #ffffff /**#000066; /**#9bc2d1;/**#7ebac9;/**#0086b3;**/



}}

[class="css-1n543e5 e1ewe7hr5"]:hover {{

    background-color: #8080ff; /**#9bc2d1;/**#7ebac9;/**#0086b3;**/

    color:white;

    border: solid 1px  #000066;

}}

a:link{{

    color:#0088be;

}}

a:hover {{

    color: #7733ff/**#8080ff**/;

}}

button{{

    padding-left:1rem;

    padding-right:1rem;

    border-radius: 15%;

}}

button:hover {{

    color:#7733ff;

    border:solid 1px #7733ff;

   

}}

</style>

"""
# head style
head_css = """

<style>

[class="css-ocqkz7 esravye3"] {

    /**background-color: #9bc2d1;**/

}

[class="css-ocqkz7 esravye3"]{

    /**row1**/

    margin:0px 0px 0px 0px;

    padding:0;

}

.stApp {

    background-image: url("portparser_brasil1.jpg");

    background-repeat: repeat;

    background-position: center;

}

</style>

"""

#class="css-o7kwkx esravye0"]

a = """

<style>

div.css-10r1649 esravye0 {

    background-color: red;

}

</style>

"""
custom_html = """

<div class="banner" style="background-color:#0088be; color:white">

<h1>PortParser</h1>

    <!--<img src="https://img.freepik.com/premium-photo/wide-banner-with-many-random-square-hexagons-charcoal-dark-black-color_105589-1820.jpg" alt="Banner Image">-->

</div>

<style>

    .banner {

        width: 160%;

        height: 200px;

        overflow: hidden;

    }

    .banner img {

        width: 100%;

        object-fit: cover;

    }

</style>

"""
#<div width="449" data-testid="stVerticalBlock" class="css-10r1649 esravye0">
#components.html(custom_html)
st.markdown(page_bg_img, unsafe_allow_html=True)
st.markdown(head_css, unsafe_allow_html=True)

row2 = st.columns([6,2,3])

with row2[0]:
    st.markdown("<p style='padding-bottom:25px; padding-top:50px'><b style='font-size:calc(40px + 2vw); color:#003d66;line-height: 40px'><i>Portparser</i></b><br><b style='font-size:18px;color:#266087;line-height:4px'>\

    A parsing model for Brazilian Portuguese</b></p>",unsafe_allow_html=True)
    st.write('This is Portparser, a parsing model for Brazilian Portuguese that follows the Universal Dependencies (UD) framework.\

    We built our model by using a recently released manually annotated corpus, the Porttinari-base, \

    and we explored different parsing methods and parameters for training. We also test multiple embedding models and parsing methods. \

    Portparse is the result of the best combination achieved in our experiments.')
    st.write('Our model is explained in the paper https://aclanthology.org/2024.propor-1.41.pdf, and all datasets and full instructions to reproduce our experiments \

    freely available at https://github.com/LuceleneL/Portparser. More details about this work may also be found at \

    the POeTiSA project webpage at https://sites.google.com/icmc.usp.br/poetisa/.')
    with st.expander('How to cite?', expanded=False):
        st.code("""

        @inproceedings{lopes2024towards,

            title={Towards Portparser-a highly accurate parsing system for Brazilian Portuguese following the Universal Dependencies framework},

            author={Lopes, Lucelene and Pardo, Thiago},

            booktitle={Proceedings of the 16th International Conference on Computational Processing of Portuguese},

            pages={401--410},

            year={2024}

        }""")
    
with row2[2]:
    st.image('img/wordcloud_brasil5.png')
#wordcloud_vertical1.png


   

#st.markdown('##### Write a sentence and run to parse:')

#with st.sidebar:
#    st.header("About Portparser")
#    with st.expander('How was Portparser developed?'):
#        st.write('We build our model by using a recently released manually annotated corpus, the Porttinari-base, \
#            and explored different parsing methods and parameters for training. We also test multiple embedding models and parsing methods. \
#            Portparse is the result of the best combination achieved in our experiments.' )

print('---------------------------')

st.markdown("""

<script language="JavaScript" type="text/javascript" src="arborator-draft.js"></script>

<script language="JavaScript" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.10.0/d3.js"></script>

<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>

<link rel="stylesheet" href="arborator-draft.css" type="text/css" />

<script src="d3.js"></script>

<script src="jquery-3.2.1.min.js"></script>

<script>

new ArboratorDraft();

</script>"""
,unsafe_allow_html=True)


def make_conllu(path_text, path_input):
    try:
        os.system(f'python portTokenizer/portTok.py -o {path_input} -m -t -s S0000 {path_text}')
        return 'Converti o texto para conllu.'
        #st.text(open(path_input,'r',encoding='utf-8').read())        
    except Exception as e:
        return str(e)
    

def make_embedding(path_input, path_embedding, model_selected):
    try:
        os.system(f'python ./wembedding_service/compute_wembeddings.py {path_input} {path_embedding} --model {model_selected}')
        return 'Fiz as embeddings.'
    except Exception as e:
        return str(e)


def make_predictions(path_input, path_prediction):
    try:
        os.system(f'python ./udpipe2/udpipe2.py Portparser_model --predict --predict_input {path_input} --predict_output {path_prediction}')
        return f'Fiz a predição.'# {path_input}, {path_prediction}'
    except Exception as e:
        return str(e)


def get_predictions(path_prediction):
    try:
        with open(path_prediction, 'r') as f:
            st.text(f.read())
    except Exception as e:
        st.text('Resposta: '+e)

st.write('Write a sentence and run to parse:')
with st.form("parser"):
    text = st.text_input('Text: ')
    model = st.selectbox('Pick a model (Pick a embedding model:):', ['bert-base-portuguese-cased','bert-base-multilingual-uncased','robeczech-base','xlm-roberta-base'])
    model_selected = model+'-last4'
    submit = st.form_submit_button('Run')

tab1, tab2, tab3, tab4 = st.tabs(["Running status" ,"Table", "Raw", "Tree"])

if submit:
    import sys, os
    print(type(text))

    tab1.text('input: '+text)

    files = 'temp'
    input_text = 'text_input.txt'
    input_conllu = 'input.conllu' #'h2104_0_test.conllu'
    embedding_conllu = 'input.conllu.npz' #'h2104_0_test.conllu.npz'
    prediction_conllu = 'input_prediction.conllu'
    model = 'Portparser_model' 

    path_text = os.path.join(files, input_text)
    path_input = os.path.join(files, input_conllu)
    path_prediction = os.path.join(files, prediction_conllu)
    path_embedding = os.path.join(files,embedding_conllu)

    with open(path_text,'w',encoding='utf-8') as f:
        f.write(text)
    import time
    with st.spinner('Transforming text into .conllu...'): #st.progress(0,text="Transformando texto para o formato .conllu"):
        time.sleep(3)
        tab1.text(make_conllu(path_text, path_input))
    with st.spinner('Processing embeddings...'): #st.progress(0,text="Processando embeddings"):
        time.sleep(6)
        tab1.text(make_embedding(path_input, path_embedding, model_selected))
    with st.spinner('Making predictions...'): #st.progress(0,text="Realizando a predição"):
        time.sleep(6)
        tab1.text(make_predictions(path_input, path_prediction))

    try:
        with open(path_prediction, 'r', encoding='utf-8') as f:
            content = f.read()
            tab3.text(content)
            #tab4.markdown(f'<conll>{content[4:]}</conll>',unsafe_allow_html=True)
            content = content.split('\n')
            #tab2.text(content[:4])
            table = pd.DataFrame([line.split('\t') for line in content[4:]])
            table.columns = ['ID','FORM','LEMMA','UPOS','XPOS','FEATS','HEAD','DEPREL','DEPS','MISC']
            tab2.dataframe(table, use_container_width=True)
    except Exception as e:
            st.text('Não deu certo a predição.'+str(e)+repr(e))



row1 = st.columns([18,3,4,4])
with row1[1]:      
    st.image('img/nilc-removebg.png')
with row1[2]:
    st.image('img/poetisa2.png')
with row1[3]:      
    st.image('img/icmc.png')



st.markdown("""

<script language="JavaScript" type="text/javascript" src="arborator-draft.js"></script>

<script language="JavaScript" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.10.0/d3.js"></script>

<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>

<link rel="stylesheet" href="arborator-draft.css" type="text/css" />

<script src="d3.js"></script>

<script src="jquery-3.2.1.min.js"></script>

<script>

new ArboratorDraft();

</script>"""
,unsafe_allow_html=True)