File size: 3,206 Bytes
f56c633 1b3a96f c170413 1b3a96f c170413 1b3a96f e84051a 1b3a96f c170413 1b3a96f c170413 1b3a96f c170413 e84051a 1b3a96f e84051a 1b3a96f e84051a 1b3a96f e84051a 1b3a96f e84051a 1b3a96f e84051a 1b3a96f c170413 e84051a 1b3a96f c170413 1b3a96f c170413 1b3a96f c170413 1b3a96f c170413 1b3a96f c170413 1b3a96f 9bd3085 20374ce c170413 1b3a96f c170413 1b3a96f c170413 1b3a96f c170413 e84051a |
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 |
import streamlit as st
from transformers import T5Tokenizer, T5ForConditionalGeneration
import torch
# Load model and tokenizer
model_path = "./saved_model"
tokenizer_path = "./saved_tokenizer"
tokenizer = T5Tokenizer.from_pretrained(tokenizer_path)
model = T5ForConditionalGeneration.from_pretrained(model_path)
# 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 for a clean, modern interface
st.markdown("""
<style>
.main {
background-color: #f0f2f6;
background-image: linear-gradient(135deg, #e6f7ff 0%, #b3e0ff 100%);
font-family: 'Arial', sans-serif;
}
.stTextArea textarea {
border: 2px solid #0078d4;
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;
}
.stTextArea textarea:focus {
border-color: #0058a3;
box-shadow: 0 0 10px #4f8bf9;
}
.stButton>button {
background-color: #29b6f6;
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;
}
.stButton>button:hover {
background-color: #0288d1;
box-shadow: 0 6px 14px rgba(2, 136, 209, 0.4);
transform: translateY(-2px);
}
.stTitle {
color: #0078d4;
font-size: 2.5em;
text-align: center;
margin-bottom: 20px;
font-family: 'Segoe UI', sans-serif;
}
.summary-container {
background-color: #ffffff;
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;
}
.summary-title {
color: #0288d1;
font-weight: bold;
font-size: 1.5em;
margin-bottom: 10px;
}
.footer {
text-align: center;
margin-top: 50px;
padding: 20px;
color: #0078d4;
font-style: italic;
}
</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)
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.")
# Footer
st.markdown("""
<div class="footer">
Created with hadheedo
</div>
""", unsafe_allow_html=True)
|