Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,7 @@ from transformers import T5Tokenizer, T5ForConditionalGeneration
|
|
3 |
import torch
|
4 |
|
5 |
# Load model and tokenizer from Hugging Face Hub
|
6 |
-
model_name = "t5-small"
|
7 |
tokenizer = T5Tokenizer.from_pretrained(model_name)
|
8 |
model = T5ForConditionalGeneration.from_pretrained(model_name)
|
9 |
|
@@ -14,21 +14,95 @@ def generate_summary(text):
|
|
14 |
outputs = model.generate(inputs.input_ids.to(model.device), max_length=150, length_penalty=2.0, num_beams=4, early_stopping=True)
|
15 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
16 |
|
17 |
-
# Custom CSS styling
|
18 |
-
st.markdown("""<style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
-
# Application UI
|
21 |
-
st.title("
|
22 |
text = st.text_area("Enter the text you want to summarize...", height=200)
|
23 |
|
24 |
-
|
25 |
-
if text:
|
26 |
-
with st.spinner("Generating summary..."):
|
27 |
-
summary = generate_summary(text)
|
28 |
-
st.markdown('<div class="summary-container"><div class="summary-title">📋 Summary</div>' +
|
29 |
-
summary + '</div>', unsafe_allow_html=True)
|
30 |
-
else:
|
31 |
-
st.warning("⚠️ Please enter text to summarize.")
|
32 |
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
st.markdown("""<div class="footer"> Created with hadheedo</div>""", unsafe_allow_html=True)
|
|
|
3 |
import torch
|
4 |
|
5 |
# Load model and tokenizer from Hugging Face Hub
|
6 |
+
model_name = "t5-small" # or your model name
|
7 |
tokenizer = T5Tokenizer.from_pretrained(model_name)
|
8 |
model = T5ForConditionalGeneration.from_pretrained(model_name)
|
9 |
|
|
|
14 |
outputs = model.generate(inputs.input_ids.to(model.device), max_length=150, length_penalty=2.0, num_beams=4, early_stopping=True)
|
15 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
16 |
|
17 |
+
# Custom CSS styling
|
18 |
+
st.markdown("""<style>
|
19 |
+
.main {
|
20 |
+
background-color: #f0f2f6;
|
21 |
+
background-image: linear-gradient(135deg, #e6f7ff 0%, #b3e0ff 100%);
|
22 |
+
font-family: 'Arial', sans-serif;
|
23 |
+
}
|
24 |
+
.stTextArea textarea {
|
25 |
+
border: 2px solid #0078d4;
|
26 |
+
border-radius: 12px;
|
27 |
+
padding: 15px;
|
28 |
+
font-family: 'Segoe UI', sans-serif;
|
29 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
30 |
+
width: 100%;
|
31 |
+
max-width: 800px;
|
32 |
+
margin: 20px auto;
|
33 |
+
font-size: 16px;
|
34 |
+
}
|
35 |
+
.stTextArea textarea:focus {
|
36 |
+
border-color: #0058a3;
|
37 |
+
box-shadow: 0 0 10px #4f8bf9;
|
38 |
+
}
|
39 |
+
.stButton>button {
|
40 |
+
background-color: #29b6f6;
|
41 |
+
color: white;
|
42 |
+
border-radius: 25px;
|
43 |
+
border: none;
|
44 |
+
padding: 12px 30px;
|
45 |
+
font-size: 18px;
|
46 |
+
font-weight: bold;
|
47 |
+
box-shadow: 0 4px 12px rgba(41, 182, 246, 0.3);
|
48 |
+
transition: all 0.3s ease;
|
49 |
+
margin-right: 10px; # Add margin to separate buttons
|
50 |
+
}
|
51 |
+
.stButton>button:hover {
|
52 |
+
background-color: #0288d1;
|
53 |
+
box-shadow: 0 6px 14px rgba(2, 136, 209, 0.4);
|
54 |
+
transform: translateY(-2px);
|
55 |
+
}
|
56 |
+
.stTitle {
|
57 |
+
color: #0078d4;
|
58 |
+
font-size: 2.5em;
|
59 |
+
text-align: center;
|
60 |
+
margin-bottom: 20px;
|
61 |
+
font-family: 'Segoe UI', sans-serif;
|
62 |
+
}
|
63 |
+
.summary-container {
|
64 |
+
background-color: #ffffff;
|
65 |
+
border-radius: 12px;
|
66 |
+
padding: 20px;
|
67 |
+
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
|
68 |
+
margin-top: 20px;
|
69 |
+
max-width: 800px;
|
70 |
+
margin: 20px auto;
|
71 |
+
}
|
72 |
+
.summary-title {
|
73 |
+
color: #0288d1;
|
74 |
+
font-weight: bold;
|
75 |
+
font-size: 1.5em;
|
76 |
+
margin-bottom: 10px;
|
77 |
+
}
|
78 |
+
.footer {
|
79 |
+
text-align: center;
|
80 |
+
margin-top: 50px;
|
81 |
+
padding: 20px;
|
82 |
+
color: #0078d4;
|
83 |
+
font-style: italic;
|
84 |
+
}
|
85 |
+
</style>""", unsafe_allow_html=True)
|
86 |
|
87 |
+
# Application UI
|
88 |
+
st.title(" Text Summarizer App")
|
89 |
text = st.text_area("Enter the text you want to summarize...", height=200)
|
90 |
|
91 |
+
col1, col2 = st.columns(2) # Create two columns for buttons
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
|
93 |
+
with col1:
|
94 |
+
if st.button("Generate Summary"):
|
95 |
+
if text:
|
96 |
+
with st.spinner("Generating summary..."):
|
97 |
+
summary = generate_summary(text)
|
98 |
+
st.markdown('<div class="summary-container"><div class="summary-title"> Summary</div>' +
|
99 |
+
summary + '</div>', unsafe_allow_html=True)
|
100 |
+
else:
|
101 |
+
st.warning("⚠️ Please enter text to summarize.")
|
102 |
+
|
103 |
+
with col2:
|
104 |
+
if st.button("Refresh"):
|
105 |
+
st.experimental_rerun() # Rerun the app to clear the summary
|
106 |
+
|
107 |
+
# Footer
|
108 |
st.markdown("""<div class="footer"> Created with hadheedo</div>""", unsafe_allow_html=True)
|