Update app.py
Browse files
app.py
CHANGED
@@ -19,4 +19,26 @@ if user_input:
|
|
19 |
with st.spinner('Generating response...'):
|
20 |
response = pipe(contexted_ipnut)
|
21 |
st.write("Response:")
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
with st.spinner('Generating response...'):
|
20 |
response = pipe(contexted_ipnut)
|
21 |
st.write("Response:")
|
22 |
+
# Initialize the highlighted text
|
23 |
+
highlighted_text = ""
|
24 |
+
last_position = 0
|
25 |
+
|
26 |
+
# Process each entity and highlight the labeled words
|
27 |
+
for entity in response:
|
28 |
+
start, end = entity['start'], entity['end']
|
29 |
+
label = entity['entity']
|
30 |
+
|
31 |
+
# Add text before the entity
|
32 |
+
highlighted_text += user_input[last_position:start]
|
33 |
+
|
34 |
+
# Add the highlighted entity
|
35 |
+
highlighted_text += f'<mark style="background-color: #FFFF00;">{user_input[start:end]}</mark><sup>{label}</sup>'
|
36 |
+
|
37 |
+
# Update the last position
|
38 |
+
last_position = end
|
39 |
+
|
40 |
+
# Add remaining text after the last entity
|
41 |
+
highlighted_text += user_input[last_position:]
|
42 |
+
|
43 |
+
# Display the highlighted text using st.markdown
|
44 |
+
st.markdown(highlighted_text, unsafe_allow_html=True)
|