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