Spaces:
Sleeping
Sleeping
import streamlit as st | |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM | |
# Load the tokenizer and model | |
tokenizer = AutoTokenizer.from_pretrained("suriya7/bart-finetuned-text-summarization") | |
model = AutoModelForSeq2SeqLM.from_pretrained("suriya7/bart-finetuned-text-summarization") | |
def generate_summary(text, prompt): | |
# Combine text and prompt into one input | |
combined_input = f"{prompt}: {text}" | |
inputs = tokenizer([combined_input], max_length=1024, return_tensors='pt', truncation=True) | |
summary_ids = model.generate(inputs['input_ids'], max_new_tokens=100, do_sample=False) | |
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True) | |
return summary | |
# Initialize session state for input history if it doesn't exist | |
if 'input_history' not in st.session_state: | |
st.session_state['input_history'] = [] | |
# Streamlit interface | |
st.title("Text Summarization App") | |
# User text inputs | |
bulk_text = st.text_area("Enter the bulk text you want to summarize", height=200) | |
prompt = st.text_input("Enter the prompt for the summary", "What are the key points?") | |
if st.button("Generate Summary"): | |
if bulk_text and prompt: | |
with st.spinner("Generating summary..."): | |
summary = generate_summary(bulk_text, prompt) | |
# Save the input and summary to the session state history | |
st.session_state['input_history'].append({"text": bulk_text, "prompt": prompt, "summary": summary}) | |
st.subheader("Generated Summary:") | |
st.write(summary) | |
else: | |
st.warning("Please enter both the bulk text and the prompt.") | |
# Display the history of inputs and summaries | |
if st.session_state['input_history']: | |
st.subheader("History") | |
for i, entry in enumerate(st.session_state['input_history']): | |
st.write(f"**Input {i+1} (Text):** {entry['text']}") | |
st.write(f"**Prompt {i+1}:** {entry['prompt']}") | |
st.write(f"**Summary {i+1}:** {entry['summary']}") | |
st.write("---") | |
# Instructions for using the app | |
st.write("Enter your bulk text and a prompt for summarization, then click 'Generate Summary' to get a summarized version based on your prompt.") | |