Spaces:
Sleeping
Sleeping
Update app.py
Browse files1234567891011from transformers import PegasusTokenizer, PegasusForConditionalGenerationmodel_name = "human-centered-summarization/financial-summarization-pegasus"tokenizer = PegasusTokenizer.from_pretrained(model_name, use_fast=False)model = PegasusForConditionalGeneration.from_pretrained(model_name)text_to_summarize = "Your text here..."input_ids = tokenizer(text_to_summarize, return_tensors="pt").input_idssummary_ids = model.generate(input_ids, max_length=60, num_beams=5, early_stopping=True)summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)print(summary)123456789101112131415161718192021222324252627282930import streamlit as stfrom transformers import pipelinedef main():# Streamlit app interface designst.title("๐ Financial Text Summarization with T5")st.write("Please enter the financial text below to generate a concise summary:")# User input area for textuser_input = st.text_area("Text Input ๐", height=300)# Initialize the summarization pipeline only once using st.session_stateif 'summarizer' not in st.session_state:# Initialize the pipeline with the T5 model for summarizationst.session_state.summarizer = pipeline("summarization", model="t5-small")# Button to generate summaryif st.button("Generate Summary"):if user_input:with st.spinner('Generating summary...'):# Generating the summary from the input textsummary_result = st.session_state.summarizer(user_input, max_length=130, min_length=30, do_sample=False)summary = summary_result[0]['summary_text']st.write("Summary ๐:")st.write(summary)else:st.error("Please enter some text to generate a summary.")if __name__ == "__main__":main()
app.py+28-9