Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,9 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import T5Tokenizer, T5ForConditionalGeneration
|
3 |
-
from transformers import T5Tokenizer
|
4 |
import torch
|
5 |
import os
|
6 |
-
import json
|
7 |
|
8 |
-
# Custom CSS styling
|
9 |
st.markdown("""
|
10 |
<style>
|
11 |
.main {
|
@@ -79,12 +77,8 @@ st.markdown("""
|
|
79 |
""", unsafe_allow_html=True)
|
80 |
|
81 |
# Load model and tokenizer
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
tokenizer = T5Tokenizer.from_pretrained("t5-small")
|
86 |
-
tokenizer.save_pretrained("./saved_tokenizer")
|
87 |
-
summary_file = "summaries.json"
|
88 |
|
89 |
try:
|
90 |
if not os.path.exists(tokenizer_path):
|
@@ -117,51 +111,31 @@ def generate_summary(text):
|
|
117 |
st.error(f"Error generating summary: {e}")
|
118 |
return None
|
119 |
|
120 |
-
|
121 |
-
if os.path.exists(summary_file):
|
122 |
-
with open(summary_file, "r", encoding="utf-8") as f:
|
123 |
-
return json.load(f)
|
124 |
-
return []
|
125 |
-
|
126 |
-
def save_summary(original, summary):
|
127 |
-
summaries = load_summaries()
|
128 |
-
summaries.append({"text": original, "summary": summary})
|
129 |
-
with open(summary_file, "w", encoding="utf-8") as f:
|
130 |
-
json.dump(summaries, f, indent=4, ensure_ascii=False)
|
131 |
|
132 |
-
|
133 |
-
|
|
|
|
|
|
|
134 |
|
135 |
-
|
136 |
-
st.title("π§ Smart Text Summarizer")
|
137 |
-
text = st.text_area("Enter the text you want to summarize...", height=200)
|
138 |
-
col1, col2, col3 = st.columns([1, 2, 1])
|
139 |
-
with col2:
|
140 |
-
if st.button("π Generate Summary"):
|
141 |
-
if text and model_loaded:
|
142 |
-
with st.spinner("Generating summary..."):
|
143 |
-
summary = generate_summary(text)
|
144 |
-
if summary:
|
145 |
-
st.markdown('<div class="summary-container"><div class="summary-title">π Summary</div>' +
|
146 |
-
summary + '</div>', unsafe_allow_html=True)
|
147 |
-
save_summary(text, summary)
|
148 |
-
else:
|
149 |
-
st.error("β Failed to generate summary. Please check your input.")
|
150 |
-
elif not model_loaded:
|
151 |
-
st.error("β Failed to load model. Please check the application logs.")
|
152 |
-
else:
|
153 |
-
st.warning("β οΈ Please enter text to summarize.")
|
154 |
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
|
|
|
|
|
|
|
|
|
|
165 |
|
166 |
st.markdown("""
|
167 |
<div class="footer">
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import T5Tokenizer, T5ForConditionalGeneration
|
|
|
3 |
import torch
|
4 |
import os
|
|
|
5 |
|
6 |
+
# Custom CSS styling for a light, elegant design
|
7 |
st.markdown("""
|
8 |
<style>
|
9 |
.main {
|
|
|
77 |
""", unsafe_allow_html=True)
|
78 |
|
79 |
# Load model and tokenizer
|
80 |
+
model_path = "./saved_model"
|
81 |
+
tokenizer_path = "./saved_tokenizer" # Define this path for saved tokenizer
|
|
|
|
|
|
|
|
|
82 |
|
83 |
try:
|
84 |
if not os.path.exists(tokenizer_path):
|
|
|
111 |
st.error(f"Error generating summary: {e}")
|
112 |
return None
|
113 |
|
114 |
+
st.title("π§ Smart Text Summarizer")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
|
116 |
+
st.markdown("""
|
117 |
+
<div style="text-align: center; margin-bottom: 30px;">
|
118 |
+
<img src="https://api.placeholder.com/300x150?text=Smart+Summary" width="300" class="header-image">
|
119 |
+
</div>
|
120 |
+
""", unsafe_allow_html=True)
|
121 |
|
122 |
+
text = st.text_area("Enter the text you want to summarize...", height=200)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
|
124 |
+
col1, col2, col3 = st.columns([1, 2, 1])
|
125 |
+
with col2:
|
126 |
+
if st.button("π Generate Summary"):
|
127 |
+
if text and model_loaded:
|
128 |
+
with st.spinner("Generating summary..."):
|
129 |
+
summary = generate_summary(text)
|
130 |
+
if summary:
|
131 |
+
st.markdown('<div class="summary-container"><div class="summary-title">π Summary</div>' +
|
132 |
+
summary + '</div>', unsafe_allow_html=True)
|
133 |
+
else:
|
134 |
+
st.error("β Failed to generate summary. Please check your input.")
|
135 |
+
elif not model_loaded:
|
136 |
+
st.error("β Failed to load model. Please check the application logs.")
|
137 |
+
else:
|
138 |
+
st.warning("β οΈ Please enter text to summarize.")
|
139 |
|
140 |
st.markdown("""
|
141 |
<div class="footer">
|