File size: 1,090 Bytes
ae7d660
ddb299c
ae7d660
ddb299c
 
 
 
ae7d660
ddb299c
 
ae7d660
ddb299c
 
ae7d660
ddb299c
 
 
 
 
 
 
 
 
 
 
 
ae7d660
 
 
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
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()