pendar02 commited on
Commit
b5db7e8
Β·
verified Β·
1 Parent(s): 2ecd393

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -2
app.py CHANGED
@@ -31,6 +31,7 @@ def load_model(model_type):
31
  try:
32
  # Clear any existing cached data
33
  gc.collect()
 
34
 
35
  device = "cpu" # Force CPU usage
36
 
@@ -150,7 +151,7 @@ def generate_summary(text, model, tokenizer):
150
  "num_beams": 4,
151
  "length_penalty": 2.0,
152
  "early_stopping": True,
153
- "no_repeat_ngram_size": 3 # Prevent repetition of phrases
154
  }
155
  )
156
 
@@ -229,7 +230,33 @@ def main():
229
  # Individual Summaries Section
230
  st.header("πŸ“ Individual Paper Summaries")
231
 
232
- # Replace the display section in main() with this:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
233
  # Display summaries with improved sorting
234
  if st.session_state.summaries is not None:
235
  col1, col2 = st.columns(2)
 
31
  try:
32
  # Clear any existing cached data
33
  gc.collect()
34
+ torch.cuda.empty_cache()
35
 
36
  device = "cpu" # Force CPU usage
37
 
 
151
  "num_beams": 4,
152
  "length_penalty": 2.0,
153
  "early_stopping": True,
154
+ "no_repeat_ngram_size": 3
155
  }
156
  )
157
 
 
230
  # Individual Summaries Section
231
  st.header("πŸ“ Individual Paper Summaries")
232
 
233
+ # Generate summaries if not already done
234
+ if st.session_state.summaries is None:
235
+ try:
236
+ with st.spinner("Generating individual paper summaries..."):
237
+ # Load summarization model
238
+ model, tokenizer = load_model("summarize")
239
+
240
+ # Generate summaries for each abstract
241
+ summaries = []
242
+ progress_bar = st.progress(0)
243
+
244
+ for idx, abstract in enumerate(df['Abstract']):
245
+ summary = generate_summary(abstract, model, tokenizer)
246
+ summaries.append(summary)
247
+ progress_bar.progress((idx + 1) / len(df))
248
+
249
+ # Store summaries in session state
250
+ st.session_state.summaries = summaries
251
+
252
+ # Cleanup
253
+ cleanup_model(model, tokenizer)
254
+ progress_bar.empty()
255
+
256
+ except Exception as e:
257
+ st.error(f"Error generating summaries: {str(e)}")
258
+ st.session_state.processing_started = False # Reset to allow retry
259
+
260
  # Display summaries with improved sorting
261
  if st.session_state.summaries is not None:
262
  col1, col2 = st.columns(2)