Update src/streamlit_app.py
Browse files- src/streamlit_app.py +42 -39
src/streamlit_app.py
CHANGED
|
@@ -1,40 +1,43 @@
|
|
| 1 |
-
import altair as alt
|
| 2 |
-
import numpy as np
|
| 3 |
-
import pandas as pd
|
| 4 |
import streamlit as st
|
| 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 |
-
st.
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
# Load model and tokenizer
|
| 6 |
+
@st.cache_resource
|
| 7 |
+
def load_model():
|
| 8 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("majorSeaweed/T5-Conv_summarisation_small")
|
| 9 |
+
tokenizer = AutoTokenizer.from_pretrained("majorSeaweed/T5-Conv_summarisation_small")
|
| 10 |
+
return tokenizer, model
|
| 11 |
+
|
| 12 |
+
tokenizer, model = load_model()
|
| 13 |
+
|
| 14 |
+
# Title
|
| 15 |
+
st.title("🧠 Dialogue Summarisation (T5)")
|
| 16 |
+
st.markdown(
|
| 17 |
+
"This app generates **non-toxic summaries** of multi-turn conversations using a SFT Tuned `t5-small` model."
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
# Input box
|
| 21 |
+
dialogue = st.text_area(
|
| 22 |
+
"Paste a conversation below (multi-turn dialogue with speaker turns):",
|
| 23 |
+
height=200,
|
| 24 |
+
placeholder="User: Hey, you there?\nBot: Yeah, what's up?\nUser: I just wanted to say you're terrible at this.",
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
# Generate summary
|
| 28 |
+
if st.button("Generate Summary"):
|
| 29 |
+
if not dialogue.strip():
|
| 30 |
+
st.warning("Please enter a conversation.")
|
| 31 |
+
else:
|
| 32 |
+
with st.spinner("Generating summary..."):
|
| 33 |
+
inputs = tokenizer(dialogue, return_tensors="pt", truncation=True, max_length=512)
|
| 34 |
+
summary_ids = model.generate(
|
| 35 |
+
**inputs,
|
| 36 |
+
max_length=60,
|
| 37 |
+
num_beams=4,
|
| 38 |
+
early_stopping=True,
|
| 39 |
+
no_repeat_ngram_size=2
|
| 40 |
+
)
|
| 41 |
+
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
| 42 |
+
st.subheader("📝 Summary")
|
| 43 |
+
st.success(summary)
|