Spaces:
Runtime error
Runtime error
File size: 1,165 Bytes
4baa579 d239c1e 4baa579 1a0ecc3 d239c1e 4baa579 d239c1e 4baa579 d239c1e 4baa579 d239c1e 4baa579 d239c1e 4baa579 d239c1e 4baa579 d239c1e 4baa579 d239c1e |
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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
import streamlit as st
from transformers import T5Tokenizer, T5ForConditionalGeneration
from transformers import pipeline
# Model and tokenizer loading
checkpoint = "./model/google/flan-t5-small" # Use the smaller "t5-small" model
tokenizer = T5Tokenizer.from_pretrained(checkpoint)
base_model = T5ForConditionalGeneration.from_pretrained(checkpoint)
# LLM pipeline
def llm_pipeline(text):
# Use the pipeline to generate the summary
pipe_sum = pipeline(
'summarization',
model=base_model,
tokenizer=tokenizer,
max_length=500,
min_length=50
)
result = pipe_sum(text)
summary = result[0]['summary_text']
return summary
# Streamlit code
st.set_page_config(layout="wide")
def main():
st.title("Document Summarization App using a Smaller Model")
# Text input area
uploaded_text = st.text_area("Paste your document text here:")
if uploaded_text:
if st.button("Summarize"):
summary = llm_pipeline(uploaded_text)
# Display the summary
st.info("Summarization Complete")
st.success(summary)
if __name__ == "__main__":
main()
|