pendar02 commited on
Commit
727832e
·
verified ·
1 Parent(s): a12289f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -0
app.py CHANGED
@@ -198,6 +198,62 @@ def improve_summary_generation(text, model, tokenizer):
198
 
199
  return summary
200
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
201
  def post_process_medical_summary(summary):
202
  """Special post-processing for medical/scientific summaries"""
203
  if not summary:
 
198
 
199
  return summary
200
 
201
+ def post_process_medical_summary(summary):
202
+ """Special post-processing for medical/scientific summaries"""
203
+ if not summary:
204
+ return summary
205
+
206
+ # Fix common medical text issues
207
+ summary = (summary
208
+ .replace(" p =", " p=") # Fix p-value spacing
209
+ .replace(" n =", " n=") # Fix sample size spacing
210
+ .replace("( ", "(") # Fix parentheses spacing
211
+ .replace(" )", ")")
212
+ .replace("vs.", "versus") # Expand abbreviations
213
+ .replace("..", ".") # Fix double periods
214
+ )
215
+
216
+ # Ensure statistical significance symbols are correct
217
+ summary = (summary
218
+ .replace("p < ", "p<")
219
+ .replace("p > ", "p>")
220
+ .replace("P < ", "p<")
221
+ .replace("P > ", "p>")
222
+ )
223
+
224
+ # Fix number formatting
225
+ summary = (summary
226
+ .replace(" +/- ", "±")
227
+ .replace(" ± ", "±")
228
+ )
229
+
230
+ # Split into sentences and process each
231
+ sentences = [s.strip() for s in summary.split('.')]
232
+ processed_sentences = []
233
+
234
+ for sentence in sentences:
235
+ if sentence:
236
+ # Capitalize first letter
237
+ sentence = sentence[0].upper() + sentence[1:] if sentence else sentence
238
+
239
+ # Fix common medical abbreviations spacing
240
+ sentence = (sentence
241
+ .replace(" et al ", " et al. ")
242
+ .replace("et al.", "et al.") # Fix double period
243
+ )
244
+
245
+ processed_sentences.append(sentence)
246
+
247
+ # Join sentences
248
+ summary = '. '.join(processed_sentences)
249
+
250
+ # Ensure proper ending
251
+ if summary and not summary.endswith('.'):
252
+ summary += '.'
253
+
254
+ return summary
255
+
256
+
257
  def post_process_medical_summary(summary):
258
  """Special post-processing for medical/scientific summaries"""
259
  if not summary: