mdasad3617's picture
Update app.py
ddb299c verified
raw
history blame
1.09 kB
import streamlit as st
from transformers import pipeline
def main():
# Set up the Streamlit app title and description
st.title("Hugging Face Model Summarization")
st.write("This app uses a Hugging Face model to summarize text. Enter your text below and click 'Summarize'.")
# Initialize the summarization pipeline from Hugging Face
summarizer = pipeline("summarization")
# Create a text area for user input
text = st.text_area("Enter text here:", placeholder="Type your text here...")
# Button to trigger summarization
if st.button("Summarize"):
if text:
try:
# Generate the summary using the Hugging Face model
summary = summarizer(text, max_length=130, min_length=30, do_sample=False)
st.write("Summary:")
st.write(summary[0]['summary_text'])
except Exception as e:
st.error(f"An error occurred during summarization: {e}")
else:
st.error("Please enter some text to summarize.")
if __name__ == "__main__":
main()