Update app.py
Browse files
app.py
CHANGED
@@ -20,8 +20,9 @@ if user_input:
|
|
20 |
response = pipe(contexted_ipnut)
|
21 |
st.write("Response:")
|
22 |
st.markdown(response)
|
23 |
-
|
24 |
-
|
|
|
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['
|
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)
|