WRX020510 commited on
Commit
9a776b6
Β·
verified Β·
1 Parent(s): 33a113b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -12
app.py CHANGED
@@ -2,29 +2,28 @@ import streamlit as st
2
  from transformers import pipeline
3
 
4
  def main():
5
- # Initialize the application interface
6
- st.title("πŸ“ˆ Financial Text Summarization with Hugging Face Spaces πŸš€")
7
- st.write("Enter a financial text to generate its summary:")
8
 
9
- # User input area
10
- user_input = st.text_area("Text Input πŸ“", height=150)
11
 
12
- # Load the summarization pipeline
13
- # Ensuring the pipeline is loaded inside the function to prevent re-loading on every interaction
14
  if 'summarizer' not in st.session_state:
15
- st.session_state['summarizer'] = pipeline("summarization", model="human-centered-summarization/financial-summarization-pegasus")
16
 
17
- # Button to trigger summarization
18
  if st.button("Generate Summary"):
19
  if user_input:
20
- # Generating summary
21
  with st.spinner('Generating summary...'):
22
- summary_result = st.session_state['summarizer'](user_input, max_length=130, min_length=30, do_sample=False)
 
23
  summary = summary_result[0]['summary_text']
24
  st.write("Summary πŸ“œ:")
25
  st.write(summary)
26
  else:
27
- st.error("Please enter some text to summarize.")
28
 
29
  if __name__ == "__main__":
30
  main()
 
2
  from transformers import pipeline
3
 
4
  def main():
5
+ # Streamlit app interface design
6
+ st.title("πŸ“ˆ Financial Text Summarization")
7
+ st.write("Please enter the financial text below to generate a concise summary:")
8
 
9
+ # User input area for text
10
+ user_input = st.text_area("Text Input πŸ“", height=300)
11
 
12
+ # Initialize the summarization pipeline only once using st.session_state
 
13
  if 'summarizer' not in st.session_state:
14
+ st.session_state.summarizer = pipeline("summarization", model="human-centered-summarization/financial-summarization-pegasus")
15
 
16
+ # Button to generate summary
17
  if st.button("Generate Summary"):
18
  if user_input:
 
19
  with st.spinner('Generating summary...'):
20
+ # Generating the summary from the input text
21
+ summary_result = st.session_state.summarizer(user_input, max_length=130, min_length=30, do_sample=False)
22
  summary = summary_result[0]['summary_text']
23
  st.write("Summary πŸ“œ:")
24
  st.write(summary)
25
  else:
26
+ st.error("Please enter some text to generate a summary.")
27
 
28
  if __name__ == "__main__":
29
  main()