|
import streamlit as st |
|
from transformers import T5Tokenizer, T5ForConditionalGeneration |
|
import torch |
|
|
|
|
|
model_name = "t5-small" |
|
tokenizer = T5Tokenizer.from_pretrained(model_name) |
|
model = T5ForConditionalGeneration.from_pretrained(model_name) |
|
|
|
|
|
def generate_summary(text): |
|
inputs = ["summarize: " + text] |
|
inputs = tokenizer(inputs, max_length=1024, truncation=True, return_tensors="pt") |
|
outputs = model.generate(inputs.input_ids.to(model.device), max_length=150, length_penalty=2.0, num_beams=4, early_stopping=True) |
|
return tokenizer.decode(outputs[0], skip_special_tokens=True) |
|
|
|
|
|
st.markdown("""<style> |
|
.main { |
|
background-color: var(--background-primary); |
|
color: var(--text-primary); |
|
font-family: 'Arial', sans-serif; |
|
} |
|
.stTextArea textarea { |
|
border: 2px solid var(--primary-color); |
|
border-radius: 12px; |
|
padding: 15px; |
|
font-family: 'Segoe UI', sans-serif; |
|
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); |
|
width: 100%; |
|
max-width: 800px; |
|
margin: 20px auto; |
|
font-size: 16px; |
|
background-color: var(--background-secondary); |
|
color: var(--text-primary); |
|
} |
|
.stTextArea textarea:focus { |
|
border-color: var(--primary-color-dark); |
|
box-shadow: 0 0 10px var(--primary-color-light); |
|
} |
|
.stButton>button { |
|
background-color: var(--primary-color); |
|
color: white; |
|
border-radius: 25px; |
|
border: none; |
|
padding: 12px 30px; |
|
font-size: 18px; |
|
font-weight: bold; |
|
box-shadow: 0 4px 12px rgba(41, 182, 246, 0.3); |
|
transition: all 0.3s ease; |
|
margin-right: 10px; |
|
} |
|
.stButton>button:hover { |
|
background-color: var(--primary-color-dark); |
|
box-shadow: 0 6px 14px rgba(2, 136, 209, 0.4); |
|
transform: translateY(-2px); |
|
} |
|
.stTitle { |
|
color: var(--primary-color); |
|
font-size: 2.5em; |
|
text-align: center; |
|
margin-bottom: 20px; |
|
font-family: 'Segoe UI', sans-serif; |
|
} |
|
.summary-container { |
|
background-color: var(--background-secondary); |
|
border-radius: 12px; |
|
padding: 20px; |
|
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1); |
|
margin-top: 20px; |
|
max-width: 800px; |
|
margin: 20px auto; |
|
color: var(--text-primary); |
|
} |
|
.summary-title { |
|
color: var(--primary-color-dark); |
|
font-weight: bold; |
|
font-size: 1.5em; |
|
margin-bottom: 10px; |
|
} |
|
.footer { |
|
text-align: center; |
|
margin-top: 50px; |
|
padding: 20px; |
|
color: var(--primary-color); |
|
font-style: italic; |
|
} |
|
|
|
@media (max-width: 600px) { |
|
.stButton>button { |
|
width: 100%; |
|
margin-right: 0; |
|
margin-bottom: 10px; |
|
} |
|
} |
|
</style>""", unsafe_allow_html=True) |
|
|
|
|
|
st.title(" Text Summarizer App") |
|
text = st.text_area("Enter the text you want to summarize...", height=200) |
|
|
|
col1, col2 = st.columns(2) |
|
|
|
with col1: |
|
if st.button("Generate Summary"): |
|
if text: |
|
with st.spinner("Generating summary..."): |
|
summary = generate_summary(text) |
|
st.markdown('<div class="summary-container"><div class="summary-title"> Summary</div>' + |
|
summary + '</div>', unsafe_allow_html=True) |
|
else: |
|
st.warning("⚠️ Please enter text to summarize.") |
|
|
|
with col2: |
|
if st.button("Refresh"): |
|
st.rerun() |
|
|
|
|
|
st.markdown("""<div class="footer"> Created with hadheedo</div>""", unsafe_allow_html=True) |