ale-dp commited on
Commit
eeddc18
1 Parent(s): 34f7b43

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -21
app.py CHANGED
@@ -1,22 +1,48 @@
1
  import streamlit as st
2
  from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
3
  import torch
4
- import sys
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  st.title("Dialog Summarizer App")
7
 
8
- # User input
9
- user_input = st.text_area("Enter the dialog:")
 
 
 
10
 
11
  # Add "Summarize" and "Clear" buttons
12
- summarize_button = st.button("Summarize")
13
- clear_button = st.button("Clear")
14
 
15
  # If "Clear" button is clicked, clear the user input
16
  if clear_button:
17
  user_input = ""
18
 
19
- # "Summarize" button and user input, generate and display summary
20
  if summarize_button and user_input:
21
  # Load pre-trained Pegasus model and tokenizer
22
  model_name = "ale-dp/pegasus-finetuned-dialog-summarizer"
@@ -26,18 +52,6 @@ if summarize_button and user_input:
26
  # Generate summary
27
  summary = generate_summary(model, tokenizer, user_input)
28
 
29
- # Display the generated summary
30
- st.subheader("Generated Summary:")
31
- st.write(summary)
32
-
33
- def generate_summary(model, tokenizer, dialogue):
34
- # Tokenize input dialogue
35
- inputs = tokenizer(dialogue, return_tensors="pt", max_length=1024, truncation=True)
36
-
37
- # Generate summary
38
- with torch.no_grad():
39
- summary_ids = model.generate(inputs["input_ids"], max_length=150, length_penalty=0.8, num_beams=4)
40
-
41
- # Decode and return the summary
42
- summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True, clean_up_tokenization_spaces=True)
43
- return summary
 
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
+ # Set page title and favicon
18
+ st.set_page_config(
19
+ page_title="Dialog Summarizer App",
20
+ page_icon=":memo:", # You can set your own emoji or use an image URL
21
+ )
22
+
23
+ # Add a logo at the top middle of the app
24
+ logo_path = "path/to/your/logo.png" # Replace with the path to your logo image file
25
+ logo_html = f'<div style="text-align:center;"><img src="ale.png" width="200"></div>'
26
+ st.markdown(logo_html, unsafe_allow_html=True)
27
+
28
+ # Display the app name below the logo
29
  st.title("Dialog Summarizer App")
30
 
31
+ # Create two columns layout
32
+ col1, col2 = st.beta_columns(2)
33
+
34
+ # User input on the left side
35
+ user_input = col1.text_area("Enter the dialog:")
36
 
37
  # Add "Summarize" and "Clear" buttons
38
+ summarize_button = col1.button("Summarize")
39
+ clear_button = col1.button("Clear")
40
 
41
  # If "Clear" button is clicked, clear the user input
42
  if clear_button:
43
  user_input = ""
44
 
45
+ # If "Summarize" button is clicked and there is user input, generate and display summary on the right side
46
  if summarize_button and user_input:
47
  # Load pre-trained Pegasus model and tokenizer
48
  model_name = "ale-dp/pegasus-finetuned-dialog-summarizer"
 
52
  # Generate summary
53
  summary = generate_summary(model, tokenizer, user_input)
54
 
55
+ # Display the generated summary on the right side
56
+ col2.subheader("Generated Summary:")
57
+ col2.write(summary)