MSey commited on
Commit
5062d6a
·
verified ·
1 Parent(s): 200336b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -20,8 +20,9 @@ if user_input:
20
  response = pipe(contexted_ipnut)
21
  st.write("Response:")
22
  st.markdown(response)
23
- # Sorting response by the 'start' position to handle overlapping entities correctly
24
- response = sorted(response, key=lambda x: x['start'])
 
25
 
26
  # Initialize the highlighted text
27
  highlighted_text = ""
@@ -29,7 +30,7 @@ if user_input:
29
 
30
  # Process each entity and highlight the labeled words
31
  for entity in response:
32
- start, end = entity['start'], entity['end']
33
  label = entity['entity']
34
 
35
  # Add text before the entity
@@ -45,4 +46,4 @@ if user_input:
45
  highlighted_text += user_input[last_position:]
46
 
47
  # Display the highlighted text using st.markdown
48
- st.markdown(highlighted_text, unsafe_allow_html=True)
 
20
  response = pipe(contexted_ipnut)
21
  st.write("Response:")
22
  st.markdown(response)
23
+ # Tokenize input to get token-level alignment
24
+ tokens = tokenizer(user_input, return_offsets_mapping=True, return_tensors='pt')
25
+ offset_mapping = tokens['offset_mapping'][0].numpy().tolist()
26
 
27
  # Initialize the highlighted text
28
  highlighted_text = ""
 
30
 
31
  # Process each entity and highlight the labeled words
32
  for entity in response:
33
+ start, end = offset_mapping[entity['index']][0], offset_mapping[entity['index']][1]
34
  label = entity['entity']
35
 
36
  # Add text before the entity
 
46
  highlighted_text += user_input[last_position:]
47
 
48
  # Display the highlighted text using st.markdown
49
+ st.markdown(highlighted_text, unsafe_allow_html=True)