ale-dp commited on
Commit
d7d5a1b
1 Parent(s): aa21d31

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -18
app.py CHANGED
@@ -1,7 +1,6 @@
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
@@ -17,12 +16,9 @@ def generate_summary(model, tokenizer, dialogue):
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")
@@ -30,32 +26,31 @@ st.title("Dialogue Summarizer App")
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"
50
- tokenizer = AutoTokenizer.from_pretrained("google/pegasus-cnn_dailymail")
51
  model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
52
 
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}")
 
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
 
16
 
17
  st.set_page_config(
18
  page_title="Dialogue Summarizer App",
19
+ page_icon="ale.png",
20
  )
21
 
 
 
 
22
 
23
  # Display the app name below the logo
24
  st.title("Dialogue Summarizer App")
 
26
  st.info("\n🖥️ Note: This application is running on CPU. Please be patient ⏳.")
27
  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.")
28
 
29
+
30
  # Create two columns layout using st.columns
31
  col1, col2 = st.columns(2)
32
 
33
  # User input on the left side with increased height
34
+ user_input = col1.text_area("Enter the dialog:", height=300)
 
 
 
 
35
 
36
  # Add "Summarize" and "Clear" buttons
37
  summarize_button = col1.button("Summarize")
38
+ clear_button = col1.button("Clear")
39
 
40
+ # If "Clear" button is clicked, clear the user input
41
+ if clear_button:
42
+ user_input = ""
43
+
44
+ # If "Summarize" button is clicked and there is user input, generate and display summary on the right side
45
  if summarize_button and user_input:
46
  # Load pre-trained Pegasus model and tokenizer
47
  model_name = "ale-dp/pegasus-finetuned-dialog-summarizer"
48
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
49
  model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
50
 
51
  # Generate summary
52
  summary = generate_summary(model, tokenizer, user_input)
53
 
54
+ # Display the generated summary on the right side
55
+ col2.subheader("Generated Summary:")
56
+ col2.write(summary)