elozano commited on
Commit
2ed1ed2
1 Parent(s): e432d6f

Move text input inside form

Browse files
Files changed (1) hide show
  1. app.py +22 -14
app.py CHANGED
@@ -21,18 +21,22 @@ def run() -> None:
21
  ner_model_name="dslim/bert-base-NER",
22
  )
23
  st.title("📰 News Analyzer")
24
- headline = st.text_input("Headline:")
25
- content = st.text_area("Content:", height=200)
26
- if headline == "":
27
- st.error("Please, provide a headline.")
28
- else:
29
- if content == "":
30
- st.warning(
31
- "Please, provide both headline and content to achieve better results."
 
 
 
 
 
 
 
32
  )
33
- button = st.button("Analyze")
34
- if button:
35
- predictions = analyzer(headline=headline, content=content)
36
  col1, _, col2 = st.columns([2, 1, 4])
37
 
38
  with col1:
@@ -53,12 +57,16 @@ def run() -> None:
53
  with col2:
54
  st.subheader("Headline:")
55
  annotated_text(
56
- *parse_entities(headline, predictions["ner"]["headline"])
 
 
57
  )
58
  st.subheader("Content:")
59
- if content:
60
  annotated_text(
61
- *parse_entities(content, predictions["ner"]["content"])
 
 
62
  )
63
  else:
64
  st.error("Content not provided.")
 
21
  ner_model_name="dslim/bert-base-NER",
22
  )
23
  st.title("📰 News Analyzer")
24
+ with st.form("news-form", clear_on_submit=False):
25
+ st.session_state.headline = st.text_input("Headline:")
26
+ st.session_state.content = st.text_area("Content:", height=200)
27
+ st.session_state.button = st.form_submit_button("Analyze")
28
+
29
+ if "button" in st.session_state:
30
+ if st.session_state.headline == "":
31
+ st.error("Please, provide a headline.")
32
+ else:
33
+ if st.session_state.content == "":
34
+ st.warning(
35
+ "Please, provide both headline and content to achieve better results."
36
+ )
37
+ predictions = analyzer(
38
+ headline=st.session_state.headline, content=st.session_state.content
39
  )
 
 
 
40
  col1, _, col2 = st.columns([2, 1, 4])
41
 
42
  with col1:
 
57
  with col2:
58
  st.subheader("Headline:")
59
  annotated_text(
60
+ *parse_entities(
61
+ st.session_state.headline, predictions["ner"]["headline"]
62
+ )
63
  )
64
  st.subheader("Content:")
65
+ if st.session_state.content:
66
  annotated_text(
67
+ *parse_entities(
68
+ st.session_state.content, predictions["ner"]["content"]
69
+ )
70
  )
71
  else:
72
  st.error("Content not provided.")