Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
3 |
+
import torch
|
4 |
+
|
5 |
+
def generate_summary(model, tokenizer, dialogue):
|
6 |
+
# Tokenize input dialogue
|
7 |
+
inputs = tokenizer(dialogue, return_tensors="pt", max_length=1024, truncation=True)
|
8 |
+
|
9 |
+
# Generate summary
|
10 |
+
with torch.no_grad():
|
11 |
+
summary_ids = model.generate(inputs["input_ids"], max_length=150, length_penalty=0.8, num_beams=4)
|
12 |
+
|
13 |
+
# Decode and return the summary
|
14 |
+
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True, clean_up_tokenization_spaces=True)
|
15 |
+
return summary
|
16 |
+
|
17 |
+
|
18 |
+
st.title("Dialog Summarizer App")
|
19 |
+
|
20 |
+
# User input
|
21 |
+
user_input = st.text_area("Enter the dialog:")
|
22 |
+
if not user_input:
|
23 |
+
st.info("Please enter a dialog.")
|
24 |
+
return
|
25 |
+
|
26 |
+
# Load pre-trained Pegasus model and tokenizer
|
27 |
+
model_name = "ale-dp/pegasus-finetuned-dialog-summarizer"
|
28 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
29 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
30 |
+
|
31 |
+
# Generate summary
|
32 |
+
summary = generate_summary(model, tokenizer, user_input)
|
33 |
+
|
34 |
+
# Display the generated summary
|
35 |
+
st.subheader("Summary:")
|
36 |
+
st.write(summary)
|