Spaces:
Sleeping
Sleeping
kargaranamir
commited on
Commit
·
595caef
1
Parent(s):
3c733b6
Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,15 @@
|
|
1 |
import streamlit as st
|
2 |
-
import torch
|
3 |
from huggingface_hub import hf_hub_download
|
4 |
from utils import *
|
5 |
|
|
|
6 |
HengamTransW = hf_hub_download(repo_id="kargaranamir/Hengam", filename="HengamTransW.pth")
|
7 |
HengamTransA = hf_hub_download(repo_id="kargaranamir/Hengam", filename="HengamTransA.pth")
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
12 |
|
13 |
# APP
|
14 |
st.set_page_config(
|
@@ -16,71 +17,63 @@ st.set_page_config(
|
|
16 |
page_icon="🕒",
|
17 |
)
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
st.markdown(
|
23 |
-
f"""
|
24 |
-
<style>
|
25 |
-
.reportview-container .main .block-container{{
|
26 |
-
{max_width_str}
|
27 |
-
}}
|
28 |
-
</style>
|
29 |
-
""",
|
30 |
-
unsafe_allow_html=True,
|
31 |
-
)
|
32 |
-
|
33 |
-
|
34 |
-
_max_width_()
|
35 |
-
|
36 |
-
c30, c31, c32 = st.columns([2.5, 1, 3])
|
37 |
-
|
38 |
-
with c30:
|
39 |
-
st.title("🕒 Hengam")
|
40 |
-
st.header("")
|
41 |
-
|
42 |
with st.expander("ℹ️ - About this app", expanded=True):
|
43 |
st.write(
|
44 |
"""
|
45 |
-
-
|
46 |
-
-
|
47 |
-
|
48 |
)
|
49 |
st.markdown("")
|
50 |
|
51 |
st.markdown("")
|
52 |
-
st.markdown("## **📌 Paste any
|
53 |
with st.form(key="my_form"):
|
54 |
-
|
|
|
55 |
with c1:
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
"Choose your model",
|
58 |
-
|
59 |
-
|
|
|
60 |
)
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
else:
|
65 |
-
ner = ner_A
|
66 |
|
67 |
with c2:
|
68 |
doc = st.text_area(
|
69 |
"Paste your text below",
|
70 |
-
|
71 |
-
height=
|
72 |
)
|
73 |
|
74 |
submit_button = st.form_submit_button(label="✨ Extract Temporal Markers!")
|
75 |
|
76 |
-
if
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
st.markdown("## **🎈Check results**")
|
82 |
-
|
83 |
-
c1, c2, c3 = st.columns([1, 3, 1])
|
84 |
-
|
85 |
-
with c2:
|
86 |
-
st.write(result)
|
|
|
1 |
import streamlit as st
|
|
|
2 |
from huggingface_hub import hf_hub_download
|
3 |
from utils import *
|
4 |
|
5 |
+
# Download the models
|
6 |
HengamTransW = hf_hub_download(repo_id="kargaranamir/Hengam", filename="HengamTransW.pth")
|
7 |
HengamTransA = hf_hub_download(repo_id="kargaranamir/Hengam", filename="HengamTransA.pth")
|
8 |
|
9 |
+
# Load models lazily
|
10 |
+
@st.cache(allow_output_mutation=True)
|
11 |
+
def load_ner_model(model_path):
|
12 |
+
return NER(model_path=model_path, tags=['B-TIM', 'I-TIM', 'B-DAT', 'I-DAT', 'O'])
|
13 |
|
14 |
# APP
|
15 |
st.set_page_config(
|
|
|
17 |
page_icon="🕒",
|
18 |
)
|
19 |
|
20 |
+
# Layout adjustments
|
21 |
+
st.markdown(
|
22 |
+
"""
|
23 |
+
<style>
|
24 |
+
.reportview-container .main .block-container {
|
25 |
+
max-width: 1400px;
|
26 |
+
}
|
27 |
+
</style>
|
28 |
+
""",
|
29 |
+
unsafe_allow_html=True,
|
30 |
+
)
|
31 |
|
32 |
+
st.markdown("## **🕒 Hengam**")
|
33 |
+
st.write("")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
with st.expander("ℹ️ - About this app", expanded=True):
|
35 |
st.write(
|
36 |
"""
|
37 |
+
- Online Demo for Hengam: An Adversarially Trained Transformer for Persian Temporal Tagging [Code](https://github.com/kargaranamir/hengam)!
|
38 |
+
- 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.
|
39 |
+
"""
|
40 |
)
|
41 |
st.markdown("")
|
42 |
|
43 |
st.markdown("")
|
44 |
+
st.markdown("## **📌 Paste any Persian (Farsi) text you want to extract its temporal markers.**")
|
45 |
with st.form(key="my_form"):
|
46 |
+
c1, c2 = st.columns([2, 3])
|
47 |
+
|
48 |
with c1:
|
49 |
+
st.write("Please wait while loading the model...")
|
50 |
+
model_paths = {
|
51 |
+
"HengamTransW.pth": "HengamTransW.pth",
|
52 |
+
"HengamTransA.pth": "HengamTransA.pth",
|
53 |
+
}
|
54 |
+
|
55 |
+
default_model = "HengamTransA.pth" # Set the default model
|
56 |
+
ModelType = st.selectbox(
|
57 |
"Choose your model",
|
58 |
+
list(model_paths.keys()),
|
59 |
+
index=list(model_paths.keys()).index(default_model), # Select the default model
|
60 |
+
help="At present, you can choose between 2 models (HengamTransW or HengamTransA) to extract temporal markers. More to come!",
|
61 |
)
|
62 |
+
|
63 |
+
ner = load_ner_model(model_paths[ModelType])
|
64 |
+
st.empty() # Clear the "Please wait" message
|
|
|
|
|
65 |
|
66 |
with c2:
|
67 |
doc = st.text_area(
|
68 |
"Paste your text below",
|
69 |
+
"Example: ساعت ۸ صبح من و علی قرار گذاشتیم که به دوشنبه بازار بریم ...",
|
70 |
+
height=80,
|
71 |
)
|
72 |
|
73 |
submit_button = st.form_submit_button(label="✨ Extract Temporal Markers!")
|
74 |
|
75 |
+
if submit_button:
|
76 |
+
result = extract_temporal_markers(doc, ner)
|
77 |
+
st.write("") # Add vertical spacing
|
78 |
+
st.markdown("## **🎈Check results**")
|
79 |
+
st.code(result, height=300) # Adjust the height here
|
|
|
|
|
|
|
|
|
|
|
|