File size: 3,135 Bytes
88db46d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57d9e70
 
34354f8
57d9e70
 
 
 
 
 
 
 
34354f8
 
 
 
 
88db46d
 
 
34354f8
57d9e70
 
 
34354f8
 
 
 
 
 
 
 
 
57d9e70
88db46d
 
29e0cfd
 
 
 
 
 
 
88db46d
57d9e70
 
 
 
29e0cfd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import streamlit as st
from transformers import pipeline
from huggingface_hub import login
from dotenv import load_dotenv
import os

# Load the environment variables from the .env file
load_dotenv()

# Retrieve the token from the .env file
huggingface_token = os.getenv("HUGGINGFACE_TOKEN")

# Log in using the retrieved token
login(token=huggingface_token)

# Available models for summarization
models = {
    "T5": "Sandaruth/T5_Full_Fine_Tuned_FINDSUM",
    "BERT": "bert-base-uncased",  # Note: BERT isn't designed for summarization; you can change this
    "LongT5": "google/long-t5-local-base",
    "Pegasus": "google/pegasus-xsum"
}

# Example texts
example_texts = {
    "Example 1": "Artificial intelligence is transforming industries by enhancing productivity and efficiency.",
    "Example 2": "Machine learning algorithms are becoming more sophisticated, allowing for better data analysis.",
    "Example 3": "Natural language processing enables machines to understand and respond to human language.",
}

# Function to count words in the input text
def count_words(text):
    return len(text.split())

# Function to copy text to clipboard
def copy_to_clipboard(text):
    st.session_state.copied_text = text  # Store copied text in session state
    st.success("Example copied to clipboard!")  # Display message

# Streamlit app layout
st.title("Summarization with Multiple Models")

# Example buttons for text selection
st.subheader("Example Texts")
for label, example in example_texts.items():
    if st.button(label):
        copy_to_clipboard(example)  # Copy the example text to clipboard

# Dropdown to select the model (bolded)
st.markdown("### **Select a model for summarization**")
model_choice = st.selectbox("", models.keys())

# Text area for input (bolded)
st.markdown("### **Enter the long text you want to summarize**")
input_text = st.text_area("", height=300)

# Button to generate the summary
if st.button("Generate Summary"):
    # Show a spinner while generating the summary
    with st.spinner("Generating summary, please wait..."):
        # Load the selected model and summarizer pipeline
        summarizer = pipeline("summarization", model=models[model_choice])
        
        # Log the model choice
        st.write(f"Using model: **{model_choice}** for summarization.")
        
        # Count and log the number of words in the input text
        word_count = count_words(input_text)
        st.write(f"Number of words in input: **{word_count}**")

        if input_text:
            # Generate the summary
            summary = summarizer(input_text, max_length=350, min_length=30, do_sample=False)
            
            # Log the success message
            st.success("Summary generated successfully!")
            
            # Display the summary
            st.subheader("Generated Summary")
            st.write(summary[0]['summary_text'])
        else:
            st.warning("Please enter text to summarize!")

# Optionally, you can add a footer or additional instructions
st.markdown("---")
st.write("Provide a long text and select a model to see the summarization in action!")