Sasidhar commited on
Commit
0a71207
1 Parent(s): 922d32d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -2
app.py CHANGED
@@ -4,6 +4,8 @@ from annotated_text import annotated_text
4
  from io import StringIO
5
  from transformers import AutoTokenizer, AutoModelForTokenClassification
6
  import os
 
 
7
  os.environ['KMP_DUPLICATE_LIB_OK']='True'
8
 
9
  import plotly.express as px
@@ -215,7 +217,7 @@ Dr Jason Sanders"""
215
 
216
  with st.sidebar:
217
  selected_menu = option_menu("Select Option",
218
- ["Upload Document", "Extract Text", "Summarize Document", "Extract Entities","Detected Barriers","Get Answers"],
219
  menu_icon="cast", default_index=0)
220
 
221
 
@@ -291,4 +293,66 @@ elif selected_menu == "Get Answers":
291
  with st.spinner("Finding Answer(s)..."):
292
  result = pipeline_qa(question=question_text, context=context)
293
  st.subheader('Answer')
294
- st.text(result['answer'])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  from io import StringIO
5
  from transformers import AutoTokenizer, AutoModelForTokenClassification
6
  import os
7
+ from streamlit_text_annotation import text_annotation
8
+
9
  os.environ['KMP_DUPLICATE_LIB_OK']='True'
10
 
11
  import plotly.express as px
 
217
 
218
  with st.sidebar:
219
  selected_menu = option_menu("Select Option",
220
+ ["Upload Document", "Extract Text", "Summarize Document", "Extract Entities","Detected Barriers","Get Answers","Annotation Tool"],
221
  menu_icon="cast", default_index=0)
222
 
223
 
 
293
  with st.spinner("Finding Answer(s)..."):
294
  result = pipeline_qa(question=question_text, context=context)
295
  st.subheader('Answer')
296
+ st.text(result['answer'])
297
+ elif selected_menu == "Annotation Tool":
298
+ data1 = {
299
+ "tokens": [
300
+ {"text": "He", "labels": ["Person"]},
301
+ {"text": "loves"},
302
+ {"text": "his"},
303
+ {"text": "dog", "labels": ["Animal", "Pet"]},
304
+ ],
305
+ "labels": [
306
+ {"text": "Person"},
307
+ {"text": "Action"},
308
+ {"text": "Animal"},
309
+ ]
310
+ }
311
+
312
+ st.subheader("Display Mode:")
313
+ left, right = st.columns(2)
314
+ with left:
315
+ st.text("Vertical labels:")
316
+ text_annotation(data1)
317
+ with right:
318
+ st.text("Horizontal labels:")
319
+ data1["labelOrientation"] = "horizontal"
320
+ text_annotation(data1)
321
+
322
+
323
+ data2 = {
324
+ "allowEditing": True,
325
+ "tokens": [
326
+ {"text": "He", "labels": ["Pronoun", "Person"]},
327
+ {"text": "loves", "labels": ["Action"]},
328
+ {"text": "his"},
329
+ {"text": "dog", "labels": ["Animal"]},
330
+ ],
331
+ "labels": [
332
+ {"text": "Pronoun", "style": {
333
+ "color": "red",
334
+ "background-color": "white",
335
+ "font-size": "8px",
336
+ "border": "3px dashed red",
337
+ }},
338
+ {"text": "Verb", "style": {
339
+ "color": "green",
340
+ "background-color": "white",
341
+ "font-size": "8px",
342
+ "font-weight": "900",
343
+ }},
344
+ {"text": "Noun", "style": {
345
+ "color": "blue",
346
+ "background-color": "white",
347
+ "font-size": "8px",
348
+ }},
349
+ {"text": "Person"},
350
+ {"text": "Animal"},
351
+ ]
352
+ }
353
+
354
+ st.subheader("Edit Mode:")
355
+ data = text_annotation(data2)
356
+ if data:
357
+ "Returned data:", data
358
+