hadheedo commited on
Commit
20374ce
Β·
verified Β·
1 Parent(s): b116003

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -51
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
- def load_summaries():
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
- # Sidebar Navigation
133
- page = st.sidebar.selectbox("Choose Page", ["Generate Summary", "Saved Summaries"])
 
 
 
134
 
135
- if page == "Generate Summary":
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
- elif page == "Saved Summaries":
156
- st.title("πŸ“š Saved Summaries")
157
- summaries = load_summaries()
158
- if summaries:
159
- for i, item in enumerate(summaries[::-1], 1):
160
- st.markdown(f"<div class='summary-container'><div class='summary-title'>πŸ“ Summary #{i}</div>"
161
- f"<strong>Original:</strong> {item['text']}<br><br>"
162
- f"<strong>Summary:</strong> {item['summary']}</div>", unsafe_allow_html=True)
163
- else:
164
- st.info("No saved summaries yet. Generate some first!")
 
 
 
 
 
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">