-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
31 lines (21 loc) · 1.28 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import streamlit as st
from utils import pipe, get_all_words_and_entities, generate_highlighted_text
# for custom CSS styling
with open('style.css') as f:
st.markdown(f'<style>{f.read()}</style>', unsafe_allow_html=True)
st.title('استخراج الكيانات المُسماة')
with st.form('submission_form'):
text = st.text_area('من فضلك ادخل النص:', placeholder='ادخل النص المراد تصنيفه...', height=80)
submitted = st.form_submit_button('تأكيد')
if submitted:
if text:
with st.spinner('...جاري التحميل'):
model_output = pipe(text, grouped_entities=True)
words = [item['word'] for item in model_output if item['word']]
entities = [item['entity_group'] for item in model_output if item['word']]
# all_words, all_entities = get_all_words_and_entities(text, words, entities)
rendered_text = generate_highlighted_text(words, entities)
st.write('<p class="bold-text"> الكيانات المُسماة: </p>', unsafe_allow_html=True)
st.markdown(rendered_text, unsafe_allow_html=True)
else:
st.error('من فضلك ادخل النص المراد تصنيفه')