Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -280,28 +280,17 @@ def get_document_checks(doc_type, template_type):
|
|
280 |
# Add other document types as needed
|
281 |
return {"required_headings": []}
|
282 |
|
283 |
-
def format_results_for_gradio(
|
284 |
-
|
285 |
-
legal_valid, incorrect_legal_references,
|
286 |
-
table_valid, incorrect_captions,
|
287 |
-
figure_valid, incorrect_fig_captions,
|
288 |
-
references_valid, incorrect_table_figure_references,
|
289 |
-
title_style_valid, incorrect_titles,
|
290 |
-
required_headings, doc_type,
|
291 |
-
double_period_valid, incorrect_sentences,
|
292 |
-
spacing_valid, incorrect_spacing,
|
293 |
-
abbreviation_issues, date_issues,
|
294 |
-
placeholder_issues):
|
295 |
-
"""Format the results for Gradio display."""
|
296 |
results = []
|
297 |
results.append("# Document Check Results\n")
|
298 |
|
299 |
# Required Headings Check
|
300 |
results.append("## Required Headings Check")
|
301 |
-
if heading_valid:
|
302 |
results.append("β
All required headings are present.\n")
|
303 |
else:
|
304 |
-
missing_headings = set(required_headings) - set(headings_found)
|
305 |
results.append("β Missing Required Headings:")
|
306 |
for heading in missing_headings:
|
307 |
results.append(f"- {heading}")
|
@@ -309,61 +298,61 @@ def format_results_for_gradio(heading_valid, headings_found,
|
|
309 |
|
310 |
# Acronym Check
|
311 |
results.append("## Acronym Check")
|
312 |
-
if acronyms_valid:
|
313 |
results.append("β
All acronyms are properly defined.\n")
|
314 |
else:
|
315 |
results.append("β The following acronyms need to be defined at first use:")
|
316 |
-
for acronym in undefined_acronyms:
|
317 |
results.append(f"- {acronym}")
|
318 |
results.append("")
|
319 |
-
|
320 |
# Legal Check
|
321 |
results.append("## Legal Terminology Check")
|
322 |
-
if legal_valid:
|
323 |
results.append("β
All legal references are properly formatted.\n")
|
324 |
else:
|
325 |
results.append("β Incorrect Legal Terminology:")
|
326 |
-
for incorrect_term, correct_term in incorrect_legal_references:
|
327 |
results.append(f"- Use '{correct_term}' instead of '{incorrect_term}'")
|
328 |
results.append("")
|
329 |
|
330 |
# Table Caption Check
|
331 |
results.append("## Table Caption Check")
|
332 |
-
if table_valid:
|
333 |
results.append("β
All table captions are correctly formatted.\n")
|
334 |
else:
|
335 |
results.append("β Incorrect Table Captions:")
|
336 |
-
for caption in incorrect_captions:
|
337 |
results.append(f"- {caption}")
|
338 |
results.append("")
|
339 |
|
340 |
# Figure Caption Check
|
341 |
results.append("## Figure Caption Check")
|
342 |
-
if figure_valid:
|
343 |
results.append("β
All figure captions are correctly formatted.\n")
|
344 |
else:
|
345 |
results.append("β Incorrect Figure Captions:")
|
346 |
-
for caption in incorrect_fig_captions:
|
347 |
results.append(f"- {caption}")
|
348 |
results.append("")
|
349 |
-
|
350 |
# Table and Figure References Check
|
351 |
results.append("## Table and Figure References Check")
|
352 |
-
if references_valid:
|
353 |
results.append("β
All table and figure references are correctly formatted.\n")
|
354 |
else:
|
355 |
results.append("β Incorrect Table/Figure References:")
|
356 |
-
for ref in incorrect_table_figure_references:
|
357 |
results.append(f"- {ref}")
|
358 |
results.append("")
|
359 |
-
|
360 |
# Document Title Style Check
|
361 |
results.append("## Document Title Style Check")
|
362 |
-
if title_style_valid:
|
363 |
results.append("β
All document title references are properly styled.\n")
|
364 |
else:
|
365 |
results.append("β Incorrect Document Title Styling:")
|
366 |
-
for title in incorrect_titles:
|
367 |
results.append(f"- {title['text']}")
|
368 |
results.append(f" - Issue: {title['issue']}")
|
369 |
|
@@ -375,6 +364,7 @@ def format_results_for_gradio(heading_valid, headings_found,
|
|
375 |
"Policy Statement": "Document titles should not have any special formatting (no italics, no quotation marks)."
|
376 |
}
|
377 |
|
|
|
378 |
if doc_type in formatting_notes:
|
379 |
results.append(f"\nNote: {formatting_notes[doc_type]}")
|
380 |
else:
|
@@ -383,51 +373,51 @@ def format_results_for_gradio(heading_valid, headings_found,
|
|
383 |
|
384 |
# Double Period Check
|
385 |
results.append("## Double Period Check")
|
386 |
-
if double_period_valid:
|
387 |
results.append("β
No double periods found.\n")
|
388 |
else:
|
389 |
results.append("β Sentences found with double periods:")
|
390 |
-
for sentence in incorrect_sentences:
|
391 |
results.append(f"- {sentence}")
|
392 |
results.append("")
|
393 |
|
394 |
# Spacing Check
|
395 |
results.append("## Spacing Check")
|
396 |
-
if spacing_valid:
|
397 |
results.append("β
All spacing is correct.\n")
|
398 |
else:
|
399 |
results.append("β Incorrect spacing found in:")
|
400 |
-
for spacing in incorrect_spacing:
|
401 |
results.append(f"- {spacing}")
|
402 |
results.append("")
|
403 |
|
404 |
# Abbreviation Consistency
|
405 |
results.append("## Abbreviation Consistency")
|
406 |
-
if not abbreviation_issues:
|
407 |
results.append("β
All abbreviations are used consistently after definition.\n")
|
408 |
else:
|
409 |
results.append("β Abbreviation Issues:")
|
410 |
-
for full_term, acronym, paragraph in abbreviation_issues:
|
411 |
results.append(f"- Use '{acronym}' instead of '{full_term}' in: {paragraph}")
|
412 |
results.append("")
|
413 |
-
|
414 |
# Date Format Consistency
|
415 |
results.append("## Date Format Consistency")
|
416 |
-
if not date_issues:
|
417 |
results.append("β
All dates are in the correct format.\n")
|
418 |
else:
|
419 |
results.append("β Date Format Issues:")
|
420 |
-
for date, paragraph in date_issues:
|
421 |
results.append(f"- Incorrect date format '{date}' in: {paragraph}")
|
422 |
results.append("")
|
423 |
-
|
424 |
# Placeholder Check
|
425 |
results.append("## Placeholder Check")
|
426 |
-
if not placeholder_issues:
|
427 |
results.append("β
No placeholders found.\n")
|
428 |
else:
|
429 |
results.append("β Placeholders Found:")
|
430 |
-
for phrase, paragraph in placeholder_issues:
|
431 |
results.append(f"- Placeholder '{phrase}' in: {paragraph}")
|
432 |
|
433 |
return "\n".join(results)
|
|
|
280 |
# Add other document types as needed
|
281 |
return {"required_headings": []}
|
282 |
|
283 |
+
def format_results_for_gradio(**kwargs):
|
284 |
+
"""Format the results for display in Gradio."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
285 |
results = []
|
286 |
results.append("# Document Check Results\n")
|
287 |
|
288 |
# Required Headings Check
|
289 |
results.append("## Required Headings Check")
|
290 |
+
if kwargs['heading_valid']:
|
291 |
results.append("β
All required headings are present.\n")
|
292 |
else:
|
293 |
+
missing_headings = set(kwargs['required_headings']) - set(kwargs['headings_found'])
|
294 |
results.append("β Missing Required Headings:")
|
295 |
for heading in missing_headings:
|
296 |
results.append(f"- {heading}")
|
|
|
298 |
|
299 |
# Acronym Check
|
300 |
results.append("## Acronym Check")
|
301 |
+
if kwargs['acronyms_valid']:
|
302 |
results.append("β
All acronyms are properly defined.\n")
|
303 |
else:
|
304 |
results.append("β The following acronyms need to be defined at first use:")
|
305 |
+
for acronym in kwargs['undefined_acronyms']:
|
306 |
results.append(f"- {acronym}")
|
307 |
results.append("")
|
308 |
+
|
309 |
# Legal Check
|
310 |
results.append("## Legal Terminology Check")
|
311 |
+
if kwargs['legal_valid']:
|
312 |
results.append("β
All legal references are properly formatted.\n")
|
313 |
else:
|
314 |
results.append("β Incorrect Legal Terminology:")
|
315 |
+
for incorrect_term, correct_term in kwargs['incorrect_legal_references']:
|
316 |
results.append(f"- Use '{correct_term}' instead of '{incorrect_term}'")
|
317 |
results.append("")
|
318 |
|
319 |
# Table Caption Check
|
320 |
results.append("## Table Caption Check")
|
321 |
+
if kwargs['table_valid']:
|
322 |
results.append("β
All table captions are correctly formatted.\n")
|
323 |
else:
|
324 |
results.append("β Incorrect Table Captions:")
|
325 |
+
for caption in kwargs['incorrect_captions']:
|
326 |
results.append(f"- {caption}")
|
327 |
results.append("")
|
328 |
|
329 |
# Figure Caption Check
|
330 |
results.append("## Figure Caption Check")
|
331 |
+
if kwargs['figure_valid']:
|
332 |
results.append("β
All figure captions are correctly formatted.\n")
|
333 |
else:
|
334 |
results.append("β Incorrect Figure Captions:")
|
335 |
+
for caption in kwargs['incorrect_fig_captions']:
|
336 |
results.append(f"- {caption}")
|
337 |
results.append("")
|
338 |
+
|
339 |
# Table and Figure References Check
|
340 |
results.append("## Table and Figure References Check")
|
341 |
+
if kwargs['references_valid']:
|
342 |
results.append("β
All table and figure references are correctly formatted.\n")
|
343 |
else:
|
344 |
results.append("β Incorrect Table/Figure References:")
|
345 |
+
for ref in kwargs['incorrect_table_figure_references']:
|
346 |
results.append(f"- {ref}")
|
347 |
results.append("")
|
348 |
+
|
349 |
# Document Title Style Check
|
350 |
results.append("## Document Title Style Check")
|
351 |
+
if kwargs['title_style_valid']:
|
352 |
results.append("β
All document title references are properly styled.\n")
|
353 |
else:
|
354 |
results.append("β Incorrect Document Title Styling:")
|
355 |
+
for title in kwargs['incorrect_titles']:
|
356 |
results.append(f"- {title['text']}")
|
357 |
results.append(f" - Issue: {title['issue']}")
|
358 |
|
|
|
364 |
"Policy Statement": "Document titles should not have any special formatting (no italics, no quotation marks)."
|
365 |
}
|
366 |
|
367 |
+
doc_type = kwargs.get('doc_type', 'Unknown')
|
368 |
if doc_type in formatting_notes:
|
369 |
results.append(f"\nNote: {formatting_notes[doc_type]}")
|
370 |
else:
|
|
|
373 |
|
374 |
# Double Period Check
|
375 |
results.append("## Double Period Check")
|
376 |
+
if kwargs['double_period_valid']:
|
377 |
results.append("β
No double periods found.\n")
|
378 |
else:
|
379 |
results.append("β Sentences found with double periods:")
|
380 |
+
for sentence in kwargs['incorrect_sentences']:
|
381 |
results.append(f"- {sentence}")
|
382 |
results.append("")
|
383 |
|
384 |
# Spacing Check
|
385 |
results.append("## Spacing Check")
|
386 |
+
if kwargs['spacing_valid']:
|
387 |
results.append("β
All spacing is correct.\n")
|
388 |
else:
|
389 |
results.append("β Incorrect spacing found in:")
|
390 |
+
for spacing in kwargs['incorrect_spacing']:
|
391 |
results.append(f"- {spacing}")
|
392 |
results.append("")
|
393 |
|
394 |
# Abbreviation Consistency
|
395 |
results.append("## Abbreviation Consistency")
|
396 |
+
if not kwargs['abbreviation_issues']:
|
397 |
results.append("β
All abbreviations are used consistently after definition.\n")
|
398 |
else:
|
399 |
results.append("β Abbreviation Issues:")
|
400 |
+
for full_term, acronym, paragraph in kwargs['abbreviation_issues']:
|
401 |
results.append(f"- Use '{acronym}' instead of '{full_term}' in: {paragraph}")
|
402 |
results.append("")
|
403 |
+
|
404 |
# Date Format Consistency
|
405 |
results.append("## Date Format Consistency")
|
406 |
+
if not kwargs['date_issues']:
|
407 |
results.append("β
All dates are in the correct format.\n")
|
408 |
else:
|
409 |
results.append("β Date Format Issues:")
|
410 |
+
for date, paragraph in kwargs['date_issues']:
|
411 |
results.append(f"- Incorrect date format '{date}' in: {paragraph}")
|
412 |
results.append("")
|
413 |
+
|
414 |
# Placeholder Check
|
415 |
results.append("## Placeholder Check")
|
416 |
+
if not kwargs['placeholder_issues']:
|
417 |
results.append("β
No placeholders found.\n")
|
418 |
else:
|
419 |
results.append("β Placeholders Found:")
|
420 |
+
for phrase, paragraph in kwargs['placeholder_issues']:
|
421 |
results.append(f"- Placeholder '{phrase}' in: {paragraph}")
|
422 |
|
423 |
return "\n".join(results)
|