File size: 3,742 Bytes
f56c633 50feb19 ac85867 50feb19 1b3a96f ac85867 62ea052 ac85867 62ea052 ac85867 62ea052 ac85867 62ea052 ac85867 62ea052 ac85867 62ea052 ac85867 62ea052 ac85867 62ea052 ac85867 62ea052 ac85867 62ea052 ac85867 62ea052 ac85867 62ea052 ac85867 62ea052 ac85867 c170413 ac85867 20374ce c170413 62ea052 c170413 ac85867 8a22004 ac85867 50feb19 |
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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
import streamlit as st
from transformers import T5Tokenizer, T5ForConditionalGeneration
import torch
# Load model and tokenizer from Hugging Face Hub
model_name = "t5-small" # or your model name
tokenizer = T5Tokenizer.from_pretrained(model_name)
model = T5ForConditionalGeneration.from_pretrained(model_name)
# Function to generate summary
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)
# Custom CSS styling
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)
# Application UI
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() # change here
# Footer
st.markdown("""<div class="footer"> Created with hadheedo</div>""", unsafe_allow_html=True) |