anasampa2 commited on
Commit
e81e0c8
1 Parent(s): be8596b

Upload app.py

Browse files

Added app.py running in vm.

Files changed (1) hide show
  1. app.py +274 -4
app.py CHANGED
@@ -1,4 +1,274 @@
1
- import streamlit as st
2
-
3
- x = st.slider('Select a value')
4
- st.write(x, 'squared is', x * x)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import streamlit.components.v1 as components
4
+ import textwrap as tw
5
+
6
+ #st.set_page_config( initial_sidebar_state="expanded", margin_top = 20, margin_left = 20, margin_right = 10, margin_bottom=50, footer_text = "Creative Commons ... " )
7
+ st.set_page_config(page_title='Portparser', layout="wide")
8
+ ##9bc2d1,#9bc2d1,#2f76a3
9
+ page_bg_img = f"""
10
+ <style>
11
+ [data-testid="stAppViewContainer"] > .main {{
12
+ background: linear-gradient(180deg, #88bbcf,#f1f1f1,#f1f1f1,#f1f1f1); /**#ccebff 10%, #f1f1f1 90% #0088be);
13
+ padding-left:4rem;
14
+ padding-right:4rem;
15
+ background-image: url("img/nilc.png");
16
+ background-repeat: repeat;
17
+ background-position: center center;
18
+ background-attachment: local;
19
+ /**#f1f1f1/** #008fb3/**#accad2;/**#b3b3ff;**/
20
+ /**background-image: url("https://i.postimg.cc/4xgNnkfX/Untitled-design.png");
21
+ background-position: center center;
22
+ background-repeat: no-repeat;
23
+ background-attachment: local;**/
24
+ }}
25
+ [data-testid="stForm"] {{
26
+ background-color: #9bc2d1;/**#7ebac9;/**#0086b3;**/
27
+ }}
28
+ .appview-container .main .block-container {{
29
+ padding-top: 1rem;
30
+ padding-bottom: 3rem;
31
+ }}
32
+ h1 {{
33
+ color:#003d66;/**#143350**/;
34
+ padding-left:1rem;
35
+ padding-right:1rem;
36
+ }}
37
+ [class="css-1n543e5 e1ewe7hr5"] {{
38
+ background-color: #ffffff /**#000066; /**#9bc2d1;/**#7ebac9;/**#0086b3;**/
39
+
40
+ }}
41
+ [class="css-1n543e5 e1ewe7hr5"]:hover {{
42
+ background-color: #8080ff; /**#9bc2d1;/**#7ebac9;/**#0086b3;**/
43
+ color:white;
44
+ border: solid 1px #000066;
45
+ }}
46
+ a:link{{
47
+ color:#0088be;
48
+ }}
49
+ a:hover {{
50
+ color: #7733ff/**#8080ff**/;
51
+ }}
52
+ button{{
53
+ padding-left:1rem;
54
+ padding-right:1rem;
55
+ border-radius: 15%;
56
+ }}
57
+ button:hover {{
58
+ color:#7733ff;
59
+ border:solid 1px #7733ff;
60
+
61
+ }}
62
+ </style>
63
+ """
64
+ # head style
65
+ head_css = """
66
+ <style>
67
+ [class="css-ocqkz7 esravye3"] {
68
+ /**background-color: #9bc2d1;**/
69
+ }
70
+ [class="css-ocqkz7 esravye3"]{
71
+ /**row1**/
72
+ margin:0px 0px 0px 0px;
73
+ padding:0;
74
+ }
75
+ .stApp {
76
+ background-image: url("portparser_brasil1.jpg");
77
+ background-repeat: repeat;
78
+ background-position: center;
79
+ }
80
+ </style>
81
+ """
82
+
83
+ #class="css-o7kwkx esravye0"]
84
+
85
+ a = """
86
+ <style>
87
+ div.css-10r1649 esravye0 {
88
+ background-color: red;
89
+ }
90
+ </style>
91
+ """
92
+ custom_html = """
93
+ <div class="banner" style="background-color:#0088be; color:white">
94
+ <h1>PortParser</h1>
95
+ <!--<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">-->
96
+ </div>
97
+ <style>
98
+ .banner {
99
+ width: 160%;
100
+ height: 200px;
101
+ overflow: hidden;
102
+ }
103
+ .banner img {
104
+ width: 100%;
105
+ object-fit: cover;
106
+ }
107
+ </style>
108
+ """
109
+ #<div width="449" data-testid="stVerticalBlock" class="css-10r1649 esravye0">
110
+ #components.html(custom_html)
111
+ st.markdown(page_bg_img, unsafe_allow_html=True)
112
+ st.markdown(head_css, unsafe_allow_html=True)
113
+
114
+ row2 = st.columns([6,2,3])
115
+
116
+ with row2[0]:
117
+ 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'>\
118
+ A parsing model for Brazilian Portuguese</b></p>",unsafe_allow_html=True)
119
+ st.write('This is Portparser, a parsing model for Brazilian Portuguese that follows the Universal Dependencies (UD) framework.\
120
+ We built our model by using a recently released manually annotated corpus, the Porttinari-base, \
121
+ and we explored different parsing methods and parameters for training. We also test multiple embedding models and parsing methods. \
122
+ Portparse is the result of the best combination achieved in our experiments.')
123
+ 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 \
124
+ freely available at https://github.com/LuceleneL/Portparser. More details about this work may also be found at \
125
+ the POeTiSA project webpage at https://sites.google.com/icmc.usp.br/poetisa/.')
126
+ with st.expander('How to cite?', expanded=False):
127
+ st.code("""
128
+ @inproceedings{lopes2024towards,
129
+ title={Towards Portparser-a highly accurate parsing system for Brazilian Portuguese following the Universal Dependencies framework},
130
+ author={Lopes, Lucelene and Pardo, Thiago},
131
+ booktitle={Proceedings of the 16th International Conference on Computational Processing of Portuguese},
132
+ pages={401--410},
133
+ year={2024}
134
+ }""")
135
+
136
+ with row2[2]:
137
+ st.image('img/wordcloud_brasil5.png')
138
+ #wordcloud_vertical1.png
139
+
140
+
141
+
142
+
143
+ #st.markdown('##### Write a sentence and run to parse:')
144
+
145
+ #with st.sidebar:
146
+ # st.header("About Portparser")
147
+ # with st.expander('How was Portparser developed?'):
148
+ # st.write('We build our model by using a recently released manually annotated corpus, the Porttinari-base, \
149
+ # and explored different parsing methods and parameters for training. We also test multiple embedding models and parsing methods. \
150
+ # Portparse is the result of the best combination achieved in our experiments.' )
151
+
152
+ print('---------------------------')
153
+
154
+ st.markdown("""
155
+ <script language="JavaScript" type="text/javascript" src="arborator-draft.js"></script>
156
+ <script language="JavaScript" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.10.0/d3.js"></script>
157
+ <script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
158
+ <link rel="stylesheet" href="arborator-draft.css" type="text/css" />
159
+ <script src="d3.js"></script>
160
+ <script src="jquery-3.2.1.min.js"></script>
161
+ <script>
162
+ new ArboratorDraft();
163
+ </script>"""
164
+ ,unsafe_allow_html=True)
165
+
166
+
167
+ def make_conllu(path_text, path_input):
168
+ try:
169
+ os.system(f'python portTokenizer/portTok.py -o {path_input} -m -t -s S0000 {path_text}')
170
+ return 'Converti o texto para conllu.'
171
+ #st.text(open(path_input,'r',encoding='utf-8').read())
172
+ except Exception as e:
173
+ return str(e)
174
+
175
+
176
+ def make_embedding(path_input, path_embedding, model_selected):
177
+ try:
178
+ os.system(f'python ./wembedding_service/compute_wembeddings.py {path_input} {path_embedding} --model {model_selected}')
179
+ return 'Fiz as embeddings.'
180
+ except Exception as e:
181
+ return str(e)
182
+
183
+
184
+ def make_predictions(path_input, path_prediction):
185
+ try:
186
+ os.system(f'python ./udpipe2/udpipe2.py Portparser_model --predict --predict_input {path_input} --predict_output {path_prediction}')
187
+ return f'Fiz a predição.'# {path_input}, {path_prediction}'
188
+ except Exception as e:
189
+ return str(e)
190
+
191
+
192
+ def get_predictions(path_prediction):
193
+ try:
194
+ with open(path_prediction, 'r') as f:
195
+ st.text(f.read())
196
+ except Exception as e:
197
+ st.text('Resposta: '+e)
198
+
199
+ st.write('Write a sentence and run to parse:')
200
+ with st.form("parser"):
201
+ text = st.text_input('Text: ')
202
+ model = st.selectbox('Pick a model (Pick a embedding model:):', ['bert-base-portuguese-cased','bert-base-multilingual-uncased','robeczech-base','xlm-roberta-base'])
203
+ model_selected = model+'-last4'
204
+ submit = st.form_submit_button('Run')
205
+
206
+ tab1, tab2, tab3, tab4 = st.tabs(["Running status" ,"Table", "Raw", "Tree"])
207
+
208
+ if submit:
209
+ import sys, os
210
+ print(type(text))
211
+
212
+ tab1.text('input: '+text)
213
+
214
+ files = 'temp'
215
+ input_text = 'text_input.txt'
216
+ input_conllu = 'input.conllu' #'h2104_0_test.conllu'
217
+ embedding_conllu = 'input.conllu.npz' #'h2104_0_test.conllu.npz'
218
+ prediction_conllu = 'input_prediction.conllu'
219
+ model = 'Portparser_model'
220
+
221
+ path_text = os.path.join(files, input_text)
222
+ path_input = os.path.join(files, input_conllu)
223
+ path_prediction = os.path.join(files, prediction_conllu)
224
+ path_embedding = os.path.join(files,embedding_conllu)
225
+
226
+ with open(path_text,'w',encoding='utf-8') as f:
227
+ f.write(text)
228
+ import time
229
+ with st.spinner('Transforming text into .conllu...'): #st.progress(0,text="Transformando texto para o formato .conllu"):
230
+ time.sleep(3)
231
+ tab1.text(make_conllu(path_text, path_input))
232
+ with st.spinner('Processing embeddings...'): #st.progress(0,text="Processando embeddings"):
233
+ time.sleep(6)
234
+ tab1.text(make_embedding(path_input, path_embedding, model_selected))
235
+ with st.spinner('Making predictions...'): #st.progress(0,text="Realizando a predição"):
236
+ time.sleep(6)
237
+ tab1.text(make_predictions(path_input, path_prediction))
238
+
239
+ try:
240
+ with open(path_prediction, 'r', encoding='utf-8') as f:
241
+ content = f.read()
242
+ tab3.text(content)
243
+ #tab4.markdown(f'<conll>{content[4:]}</conll>',unsafe_allow_html=True)
244
+ content = content.split('\n')
245
+ #tab2.text(content[:4])
246
+ table = pd.DataFrame([line.split('\t') for line in content[4:]])
247
+ table.columns = ['ID','FORM','LEMMA','UPOS','XPOS','FEATS','HEAD','DEPREL','DEPS','MISC']
248
+ tab2.dataframe(table, use_container_width=True)
249
+ except Exception as e:
250
+ st.text('Não deu certo a predição.'+str(e)+repr(e))
251
+
252
+
253
+
254
+ row1 = st.columns([18,3,4,4])
255
+ with row1[1]:
256
+ st.image('img/nilc-removebg.png')
257
+ with row1[2]:
258
+ st.image('img/poetisa2.png')
259
+ with row1[3]:
260
+ st.image('img/icmc.png')
261
+
262
+
263
+
264
+ st.markdown("""
265
+ <script language="JavaScript" type="text/javascript" src="arborator-draft.js"></script>
266
+ <script language="JavaScript" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.10.0/d3.js"></script>
267
+ <script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
268
+ <link rel="stylesheet" href="arborator-draft.css" type="text/css" />
269
+ <script src="d3.js"></script>
270
+ <script src="jquery-3.2.1.min.js"></script>
271
+ <script>
272
+ new ArboratorDraft();
273
+ </script>"""
274
+ ,unsafe_allow_html=True)