Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 3 |
+
import torch
|
| 4 |
+
import nltk
|
| 5 |
+
|
| 6 |
+
# Download punkt for sentence tokenization
|
| 7 |
+
nltk.download('punkt')
|
| 8 |
+
|
| 9 |
+
# Load tokenizer and model from the Hugging Face Hub
|
| 10 |
+
tokenizer = AutoTokenizer.from_pretrained("your-huggingface-username/your-model-repo-name")
|
| 11 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("your-huggingface-username/your-model-repo-name")
|
| 12 |
+
|
| 13 |
+
st.title("Dialogue Summarization with BART")
|
| 14 |
+
|
| 15 |
+
# Input dialogue
|
| 16 |
+
dialogue = st.text_area("Enter dialogue:", height=200)
|
| 17 |
+
|
| 18 |
+
if st.button("Summarize"):
|
| 19 |
+
# Tokenize input
|
| 20 |
+
inputs = tokenizer(dialogue, max_length=512, truncation=True, return_tensors="pt")
|
| 21 |
+
|
| 22 |
+
# Generate summary
|
| 23 |
+
summary_ids = model.generate(inputs["input_ids"], max_length=128, num_beams=4, early_stopping=True)
|
| 24 |
+
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
| 25 |
+
|
| 26 |
+
# Display summary
|
| 27 |
+
st.subheader("Summary:")
|
| 28 |
+
st.write(summary)
|
| 29 |
+
|
| 30 |
+
st.markdown("---")
|
| 31 |
+
st.markdown("This app uses a fine-tuned BART model to summarize dialogues. The model was trained on the SAMSum dataset.")
|