File size: 932 Bytes
104fe94
 
 
 
 
 
54c3649
 
 
104fe94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM

# Load the tokenizer and model
@st.cache_resource
def load_model():
    model_path = "./bart_samsum"  # Local directory where the model is stored
    tokenizer = AutoTokenizer.from_pretrained(model_path)
    model = AutoModelForSeq2SeqLM.from_pretrained(model_path)
    return tokenizer, model

tokenizer, model = load_model()

st.title("Summarization with BART")

# Text input
dialogue = st.text_area("Enter the dialogue to summarize:", height=200)

# Summarize button
if st.button("Summarize"):
    inputs = tokenizer(dialogue, max_length=512, truncation=True, return_tensors="pt")
    summary_ids = model.generate(inputs["input_ids"], max_length=128, min_length=30, length_penalty=2.0, num_beams=4, early_stopping=True)
    summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
    st.write("### Summary")
    st.write(summary)