File size: 2,668 Bytes
fbe9f3b
c2d0268
fbe9f3b
 
 
6a90715
 
 
 
 
595caef
 
 
 
 
 
 
 
 
 
 
6a90715
595caef
 
6a90715
 
 
595caef
 
 
6a90715
 
 
e0d7f27
f365795
 
 
 
 
e0d7f27
 
 
 
 
 
 
 
 
f365795
 
6a90715
595caef
6a90715
595caef
 
6a90715
595caef
8d072c5
 
595caef
 
 
 
6a90715
595caef
 
 
6a90715
595caef
 
6a90715
 
 
1cf8f8b
595caef
 
6a90715
 
 
 
595caef
e0d7f27
595caef
03817b1
e4c022f
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import streamlit as st
from huggingface_hub import hf_hub_download
from utils import *

# APP
st.set_page_config(
    page_title="Hengam",
    page_icon="🕒",
)

# Layout adjustments
st.markdown(
    """
<style>
.reportview-container .main .block-container {
    max-width: 1400px;
}
</style>
""",
    unsafe_allow_html=True,
)

st.markdown("## **🕒 Hengam**")
st.write("")
with st.expander("ℹ️ - About this app", expanded=True):
    st.write(
        """     
- Online Demo for Hengam: An Adversarially Trained Transformer for Persian Temporal Tagging [Code](https://github.com/kargaranamir/hengam)!
- This paper introduces Hengam, an adversarially trained transformer for Persian temporal tagging outperforming state-of-the-art approaches on a diverse and manually created dataset.
    """
    )
    st.markdown("")

    
# Load models lazily
@st.cache(allow_output_mutation=True)
def load_ner_model(model_path):
    return NER(model_path=model_path, tags=['B-TIM', 'I-TIM', 'B-DAT', 'I-DAT', 'O'])

with st.spinner(text="Please wait while the model is loading...."):

    # Download the models
    HengamTransW = hf_hub_download(repo_id="kargaranamir/Hengam", filename="HengamTransW.pth")
    HengamTransA = hf_hub_download(repo_id="kargaranamir/Hengam", filename="HengamTransA.pth")

    # cache
    load_ner_model(HengamTransW)
    load_ner_model(HengamTransA)


st.markdown("")
st.markdown("## **📌 Paste any Persian (Farsi) text you want to extract its temporal markers.**")
with st.form(key="my_form"):
    c1, c2 = st.columns([2, 3])
    
    with c1:
        model_paths = {
            "HengamTransW.pth": HengamTransW,
            "HengamTransA.pth": HengamTransA,
        }
        
        default_model = "HengamTransA.pth"  # Set the default model
        ModelType = st.selectbox(
            "Choose your model",
            list(model_paths.keys()),
            index=list(model_paths.keys()).index(default_model),  # Select the default model
            help="At present, you can choose between 2 models (HengamTransW or HengamTransA) to extract temporal markers. More to come!",
        )
        
        ner = load_ner_model(model_paths[ModelType])

    with c2:
        doc = st.text_area(
            "Paste your text below",
            "Example: ساعت ۸ صبح من و علی قرار گذاشتیم که به دوشنبه بازار بریم ...",
            height=80,
        )

        submit_button = st.form_submit_button(label="✨ Extract Temporal Markers!")

if submit_button:
    result = ner("# " + doc)
    st.write("")  # Add vertical spacing
    st.markdown("**Result:**")
    st.code(result, language="python")