Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,30 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
| 3 |
|
| 4 |
+
def main():
|
| 5 |
+
# Streamlit app interface design
|
| 6 |
+
st.title("๐ Financial Text Summarization with T5")
|
| 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 |
+
# Initialize the pipeline with the T5 model for summarization
|
| 15 |
+
st.session_state.summarizer = pipeline("summarization", model="t5-small")
|
| 16 |
+
|
| 17 |
+
# Button to generate summary
|
| 18 |
+
if st.button("Generate Summary"):
|
| 19 |
+
if user_input:
|
| 20 |
+
with st.spinner('Generating summary...'):
|
| 21 |
+
# Generating the summary from the input text
|
| 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 generate a summary.")
|
| 28 |
+
|
| 29 |
+
if __name__ == "__main__":
|
| 30 |
+
main()
|