Spaces:
Sleeping
Sleeping
Upload Dialogue Examples
Browse files- app.py +21 -21
- examples.py +28 -0
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
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
|
@@ -14,39 +15,35 @@ def generate_summary(model, tokenizer, dialogue):
|
|
14 |
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True, clean_up_tokenization_spaces=True)
|
15 |
return summary
|
16 |
|
17 |
-
# Set page title and favicon
|
18 |
st.set_page_config(
|
19 |
-
page_title="
|
20 |
-
page_icon="
|
21 |
)
|
22 |
|
23 |
-
#
|
24 |
-
|
25 |
-
logo_html =
|
26 |
-
st.markdown(logo_html, unsafe_allow_html=True)
|
27 |
|
28 |
# Display the app name below the logo
|
29 |
-
st.title("
|
30 |
-
|
31 |
-
st.info("🖥️ Note: This application is running on CPU. Please be patient ⏳.")
|
32 |
-
st.markdown("This app summarizes dialogues. Enter a dialogue in the text area, and the generated summary will appear at the bottom. Keep the dialogues few sentences long for optimal results.")
|
33 |
|
|
|
|
|
34 |
|
35 |
# Create two columns layout using st.columns
|
36 |
col1, col2 = st.columns(2)
|
37 |
|
38 |
# User input on the left side with increased height
|
39 |
-
user_input = col1.text_area("Enter
|
|
|
|
|
|
|
|
|
40 |
|
41 |
# Add "Summarize" and "Clear" buttons
|
42 |
summarize_button = col1.button("Summarize")
|
43 |
-
clear_button = col1.button("Clear")
|
44 |
|
45 |
-
# If "
|
46 |
-
if clear_button:
|
47 |
-
user_input = ""
|
48 |
-
|
49 |
-
# If "Summarize" button is clicked and there is user input, generate and display summary on the right side
|
50 |
if summarize_button and user_input:
|
51 |
# Load pre-trained Pegasus model and tokenizer
|
52 |
model_name = "ale-dp/pegasus-finetuned-dialog-summarizer"
|
@@ -56,6 +53,9 @@ if summarize_button and user_input:
|
|
56 |
# Generate summary
|
57 |
summary = generate_summary(model, tokenizer, user_input)
|
58 |
|
59 |
-
#
|
60 |
-
|
61 |
-
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
3 |
import torch
|
4 |
+
from examples import dialogue_examples
|
5 |
|
6 |
def generate_summary(model, tokenizer, dialogue):
|
7 |
# Tokenize input dialogue
|
|
|
15 |
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True, clean_up_tokenization_spaces=True)
|
16 |
return summary
|
17 |
|
|
|
18 |
st.set_page_config(
|
19 |
+
page_title="Dialogue Summarizer App",
|
20 |
+
page_icon="ale.png", # You can set your own emoji or use an image URL
|
21 |
)
|
22 |
|
23 |
+
#logo_path = "ale.png"
|
24 |
+
#logo_html = f'<div style="text-align:center;"><img src="{logo_path}" width="200"></div>'
|
25 |
+
#st.markdown(logo_html, unsafe_allow_html=True)
|
|
|
26 |
|
27 |
# Display the app name below the logo
|
28 |
+
st.title("Dialogue Summarizer App")
|
|
|
|
|
|
|
29 |
|
30 |
+
st.info("\n🖥️ Note: This application is running on CPU. Please be patient ⏳.")
|
31 |
+
st.markdown("This app summarizes dialogues. Enter a short dialogue in the text area. For best results, keep the dialogues at least a few sentences. You can also use the examples provided at the bottom of the page.")
|
32 |
|
33 |
# Create two columns layout using st.columns
|
34 |
col1, col2 = st.columns(2)
|
35 |
|
36 |
# User input on the left side with increased height
|
37 |
+
user_input = col1.text_area("Enter a Dialogue:", height=300)
|
38 |
+
|
39 |
+
# Summary textbox on the right side with initial value (read-only)
|
40 |
+
initial_summary = "Generated Summary will appear here."
|
41 |
+
generated_summary = col2.text_area("Summary:", value=initial_summary, height=300, key="summary")
|
42 |
|
43 |
# Add "Summarize" and "Clear" buttons
|
44 |
summarize_button = col1.button("Summarize")
|
|
|
45 |
|
46 |
+
# If "Summarize" button is clicked and there is user input, generate and display summary in the summary textbox
|
|
|
|
|
|
|
|
|
47 |
if summarize_button and user_input:
|
48 |
# Load pre-trained Pegasus model and tokenizer
|
49 |
model_name = "ale-dp/pegasus-finetuned-dialog-summarizer"
|
|
|
53 |
# Generate summary
|
54 |
summary = generate_summary(model, tokenizer, user_input)
|
55 |
|
56 |
+
# Update the summary textbox with the generated summary
|
57 |
+
generated_summary.text(summary)
|
58 |
+
|
59 |
+
st.markdown("**Dialogue examples:**")
|
60 |
+
for idx, example in enumerate(dialogue_examples, 1):
|
61 |
+
st.write(f"Example {idx}:\n{example}")
|
examples.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
dialogue_examples = [
|
2 |
+
("Ernest: hey Mike, did you park your car on our street? Mike: no, took it"
|
3 |
+
" into garage today Ernest: ok good Mike: why? Ernest: someone just crashed"
|
4 |
+
" into a red honda looking just like yours Mike: lol lucky me."),
|
5 |
+
|
6 |
+
("Laura: Where are you? Paul: Almost there. Laura: Which is? Paul: Close to"
|
7 |
+
" the Mac. Laura: That's so far away! Paul: 15 mins Laura: I am not waiting"
|
8 |
+
" any more, see you some other time. Paul: Please, wait! Laura: I've waited"
|
9 |
+
" 30 minutes, 15 minutes ago you wrote you were almost here. This is too"
|
10 |
+
" much. Paul: I am so sorry. Laura: I am not."),
|
11 |
+
|
12 |
+
("Lola: hey girlfriend, what's up? Adele: Oh, hi Lols, not much. Adele: got"
|
13 |
+
" a new dog. Lola: another one? Adele: Yup. a pup biscuit lab. 4 months."
|
14 |
+
" Chewy. Lola: how did the others react? Adele: the cats keep their"
|
15 |
+
" distance, Poppy and Lulu seem to mother him. Speedy wants to play. Lola:"
|
16 |
+
" no fighting? that's new. Adele: they say puppies are accepted by other"
|
17 |
+
" animals more easily than older dogs Lola: especially girl dogs, probably"
|
18 |
+
" Adele: with the other ones I had to wean them because I took them in as"
|
19 |
+
" adult dogs. And girls like to fight. like crazy. Lola: doggies, right/."
|
20 |
+
" Adele: that too :P Lola: haha. true though. Adele: I know, right. Anyway,"
|
21 |
+
" called him Bones. He's so plump it kinda fit. Lola: cute. can't wait to"
|
22 |
+
" see him."),
|
23 |
+
|
24 |
+
(" Ali: I think I left my wallet at your place yesterday. Could you check?"
|
25 |
+
" Garcia: Give me a sec, I'll have a look around my room. Ali: OK. Garcia:"
|
26 |
+
" Found it! Ali: Phew, I don't know what I'd do if it wasn't there. Can you"
|
27 |
+
" bring it to uni tomorrow? Garcia: Sure thing.")
|
28 |
+
]
|