|
import streamlit as st |
|
from transformers import pipeline, set_seed |
|
|
|
def generate_summary(text): |
|
|
|
summarizer = pipeline("summarization", model="t5-base", max_length=1024, min_length=40) |
|
|
|
|
|
set_seed(1) |
|
|
|
|
|
summary = summarizer(text, num_beams=4, no_repeat_ngram_size=2, length_penalty=2.0, early_stopping=True)[0]['summary_text'] |
|
|
|
return summary |
|
|
|
def main(): |
|
|
|
st.title("Text Summarizer") |
|
|
|
|
|
input_text = st.text_area("Enter text to summarize", "") |
|
|
|
|
|
if st.button("Summarize"): |
|
|
|
if input_text: |
|
summary = generate_summary(input_text) |
|
st.write(summary) |
|
else: |
|
st.warning("Please enter some text to summarize.") |
|
|
|
if __name__ == "__main__": |
|
main() |
|
|