Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -868,29 +868,44 @@ class FAADocumentChecker(DocumentChecker):
|
|
| 868 |
def process_document(file_obj, doc_type: str, template_type: Optional[str] = None) -> str:
|
| 869 |
"""Process document and run all checks."""
|
| 870 |
try:
|
|
|
|
| 871 |
checker = FAADocumentChecker()
|
| 872 |
|
|
|
|
| 873 |
if isinstance(file_obj, bytes):
|
| 874 |
file_obj = io.BytesIO(file_obj)
|
| 875 |
|
|
|
|
| 876 |
results = checker.run_all_checks(file_obj, doc_type, template_type)
|
| 877 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 878 |
|
| 879 |
except Exception as e:
|
| 880 |
logging.error(f"Error processing document: {str(e)}")
|
| 881 |
traceback.print_exc()
|
| 882 |
-
|
| 883 |
-
|
| 884 |
-
|
| 885 |
-
|
| 886 |
-
|
| 887 |
-
|
| 888 |
-
|
| 889 |
-
|
| 890 |
-
3. The file is properly formatted
|
| 891 |
-
|
| 892 |
-
Try again after checking these issues. If the problem persists, contact support.
|
| 893 |
-
"""
|
| 894 |
|
| 895 |
def format_markdown_results(results: Dict[str, DocumentCheckResult], doc_type: str) -> str:
|
| 896 |
"""Format check results into a Markdown string for Gradio display."""
|
|
|
|
| 868 |
def process_document(file_obj, doc_type: str, template_type: Optional[str] = None) -> str:
|
| 869 |
"""Process document and run all checks."""
|
| 870 |
try:
|
| 871 |
+
# Initialize checker
|
| 872 |
checker = FAADocumentChecker()
|
| 873 |
|
| 874 |
+
# Convert file object to BytesIO if needed
|
| 875 |
if isinstance(file_obj, bytes):
|
| 876 |
file_obj = io.BytesIO(file_obj)
|
| 877 |
|
| 878 |
+
# Run all checks
|
| 879 |
results = checker.run_all_checks(file_obj, doc_type, template_type)
|
| 880 |
+
|
| 881 |
+
# Format results using DocumentCheckResultsFormatter
|
| 882 |
+
formatter = DocumentCheckResultsFormatter()
|
| 883 |
+
formatted_results = formatter.format_results(results, doc_type)
|
| 884 |
+
|
| 885 |
+
# Convert the formatted results to HTML
|
| 886 |
+
html_content = f"""
|
| 887 |
+
<div id="document-checker-results"></div>
|
| 888 |
+
<script type="module">
|
| 889 |
+
import DocumentCheckerResults from './components/DocumentCheckerResults.jsx';
|
| 890 |
+
const results = {json.dumps(formatted_results)};
|
| 891 |
+
const root = document.getElementById('document-checker-results');
|
| 892 |
+
ReactDOM.render(React.createElement(DocumentCheckerResults, {{ results }}), root);
|
| 893 |
+
</script>
|
| 894 |
+
"""
|
| 895 |
+
|
| 896 |
+
return html_content
|
| 897 |
|
| 898 |
except Exception as e:
|
| 899 |
logging.error(f"Error processing document: {str(e)}")
|
| 900 |
traceback.print_exc()
|
| 901 |
+
error_html = f"""
|
| 902 |
+
<div class="error-message" style="color: red; padding: 1rem;">
|
| 903 |
+
❌ Error processing document: {str(e)}
|
| 904 |
+
<br><br>
|
| 905 |
+
Please ensure the file is a valid .docx document and try again.
|
| 906 |
+
</div>
|
| 907 |
+
"""
|
| 908 |
+
return error_html
|
|
|
|
|
|
|
|
|
|
|
|
|
| 909 |
|
| 910 |
def format_markdown_results(results: Dict[str, DocumentCheckResult], doc_type: str) -> str:
|
| 911 |
"""Format check results into a Markdown string for Gradio display."""
|