File size: 2,419 Bytes
88db46d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f2af6e2
 
e6ddaee
88db46d
 
 
 
57d9e70
 
 
 
88db46d
 
 
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
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_Full_FineTune_V0.1_40K": "ARSynopsis/T5_Full_FineTune_V0.1_40K",
    "T5_Full_FineTune_V0.1_80K": "ARSynopsis/T5_Full_FineTune_V0.1_80K",
    "BART_Base_Full_FineTune_V0.1_83K": "ARSynopsis/BART_Base_Full_FineTune_V0.1_83K",
    "LongT5": "google/long-t5-local-base",
    "Pegasus": "google/pegasus-xsum"
}

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

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

# 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!")