Spaces:
Sleeping
Sleeping
Updated version 2.0
Browse files1 unmodified line2345678910111 unmodified line131415161718192021222324252627282930312 unmodified lines343536373839404142434445464748495051523 unmodified lines5657581 unmodified lineimport streamlit as stfrom transformers import BartTokenizer, TFBartForConditionalGeneration# Suppress TensorFlow logging for errors onlyos.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'# Load the model and tokenizermodel_name = 'facebook-bart-large-cnn'tokenizer = BartTokenizer.from_pretrained(model_name)model = TFBartForConditionalGeneration.from_pretrained(model_name)1 unmodified linedef summarize(text, style):input_length = len(tokenizer.encode(text, return_tensors='tf', max_length=1024, truncation=True)[0])# Calculate max_length based on the chosen styleif style == 'Accurate':max_length = int(input_length * 0.3) # Less than one-thirdmin_length = int(input_length * 0.2)length_penalty = 1.0elif style == 'Precise':max_length = int(input_length * 0.33) # One-thirdmin_length = int(input_length * 0.25)length_penalty = 1.2else: # Normalmax_length = int(input_length * 0.5) # Half the lengthmin_length = int(input_length * 0.4)length_penalty = 1.5inputs = tokenizer.encode(text, return_tensors='tf', max_length=1024, truncation=True)summary_ids = model.generate(2 unmodified linesmin_length=min_length,length_penalty=length_penalty,num_beams=4,early_stopping=True)summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True, clean_up_tokenization_spaces=True)return summary# Streamlit appst.title('Text Summarizer')user_input = st.text_area("Enter text to summarize:", "")# Dropdown menu for summarization stylesummary_style = st.selectbox('Choose summarization style:',('Accurate', 'Precise', 'Normal'))if st.button('Summarize'):3 unmodified linesst.write(summary)else:st.write("Please enter some text to summarize.")1 unmodified line23456781 unmodified line1011121314151617181920212223242526272 unmodified lines30313233343536373839404142434445464748493 unmodified lines53545556571 unmodified lineimport streamlit as stfrom transformers import BartTokenizer, TFBartForConditionalGenerationos.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'model_name = 'facebook-bart-large-cnn'tokenizer = BartTokenizer.from_pretrained(model_name)model = TFBartForConditionalGeneration.from_pretrained(model_name)1 unmodified linedef summarize(text, style):input_length = len(tokenizer.encode(text, return_tensors='tf', max_length=1024, truncation=True)[0])if style == 'Normal':max_length = int(input_length * 0.6)min_length = int(input_length * 0.5)length_penalty = 1.5elif style == 'Precise':max_length = int(input_length * 0.45)min_length = int(input_length * 0.35)length_penalty = 1.2else:max_length = int(input_length * 0.4)min_length = int(input_length * 0.3)length_penalty = 1.0inputs = tokenizer.encode(text, return_tensors='tf', max_length=1024, truncation=True)summary_ids = model.generate(2 unmodified linesmin_length=min_length,length_penalty=length_penalty,num_beams=4,no_repeat_ngram_size=3,early_stopping=True)summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True, clean_up_tokenization_spaces=True)if not summary.endswith(('.', '!', '?')):summary += '.'return summaryst.title('Text Summarizer')user_input = st.text_area("Enter text to summarize:", "")summary_style = st.selectbox('Choose summarization style:',('Normal', 'Precise', 'Accurate'))if st.button('Summarize'):3 unmodified linesst.write(summary)else:st.write("Please enter some text to summarize.")# End of program 2.0
app.py+17-18