text_sum1 / app.py
sharath6900's picture
Update app.py
944e2ee verified
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.")