Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,23 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# Load the
|
| 5 |
-
summarizer = pipeline("summarization", model="t5-small"
|
| 6 |
|
| 7 |
def summarize_text(text):
|
| 8 |
-
"""Summarize the input text using
|
| 9 |
summary = summarizer(text, max_length=150, min_length=50, do_sample=False)
|
| 10 |
return summary[0]['summary_text']
|
| 11 |
|
| 12 |
# Streamlit UI
|
| 13 |
-
st.title("Text Summarization with
|
| 14 |
|
| 15 |
st.write("Enter the text you want to summarize:")
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
# Text input from the user
|
| 18 |
user_input = st.text_area("Input Text", height=200)
|
| 19 |
|
|
@@ -21,7 +25,21 @@ if st.button("Summarize"):
|
|
| 21 |
if user_input:
|
| 22 |
# Generate summary
|
| 23 |
summary = summarize_text(user_input)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
st.subheader("Summary:")
|
| 25 |
st.write(summary)
|
| 26 |
else:
|
| 27 |
st.error("Please enter some text to summarize.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load the summarization pipeline with a different model
|
| 5 |
+
summarizer = pipeline("summarization", model="t5-small")
|
| 6 |
|
| 7 |
def summarize_text(text):
|
| 8 |
+
"""Summarize the input text using Hugging Face's pipeline."""
|
| 9 |
summary = summarizer(text, max_length=150, min_length=50, do_sample=False)
|
| 10 |
return summary[0]['summary_text']
|
| 11 |
|
| 12 |
# Streamlit UI
|
| 13 |
+
st.title("Text Summarization with Hugging Face")
|
| 14 |
|
| 15 |
st.write("Enter the text you want to summarize:")
|
| 16 |
|
| 17 |
+
# Initialize history in session state if not already done
|
| 18 |
+
if 'history' not in st.session_state:
|
| 19 |
+
st.session_state.history = []
|
| 20 |
+
|
| 21 |
# Text input from the user
|
| 22 |
user_input = st.text_area("Input Text", height=200)
|
| 23 |
|
|
|
|
| 25 |
if user_input:
|
| 26 |
# Generate summary
|
| 27 |
summary = summarize_text(user_input)
|
| 28 |
+
|
| 29 |
+
# Save to history
|
| 30 |
+
st.session_state.history.append({"input": user_input, "summary": summary})
|
| 31 |
+
|
| 32 |
st.subheader("Summary:")
|
| 33 |
st.write(summary)
|
| 34 |
else:
|
| 35 |
st.error("Please enter some text to summarize.")
|
| 36 |
+
|
| 37 |
+
# Display history
|
| 38 |
+
st.subheader("Summary History:")
|
| 39 |
+
if st.session_state.history:
|
| 40 |
+
for entry in st.session_state.history:
|
| 41 |
+
st.write(f"**Input Text:** {entry['input']}")
|
| 42 |
+
st.write(f"**Summary:** {entry['summary']}")
|
| 43 |
+
st.write("---")
|
| 44 |
+
else:
|
| 45 |
+
st.write("No summaries available yet.")
|