Update app.py
Browse files
app.py
CHANGED
@@ -291,6 +291,8 @@ def highlight_issues_in_pdf(file, language_matches: List[Dict[str, Any]]) -> byt
|
|
291 |
# Main Analysis Function
|
292 |
# ------------------------------
|
293 |
|
|
|
|
|
294 |
def analyze_pdf(filepath: str) -> Tuple[Dict[str, Any], bytes]:
|
295 |
"""Analyzes the PDF for language issues and returns results and annotated PDF."""
|
296 |
try:
|
@@ -299,12 +301,21 @@ def analyze_pdf(filepath: str) -> Tuple[Dict[str, Any], bytes]:
|
|
299 |
return {"error": "Failed to extract text from PDF."}, None
|
300 |
|
301 |
language_issues = check_language_issues(full_text)
|
|
|
|
|
|
|
|
|
|
|
|
|
302 |
|
303 |
-
if
|
304 |
-
|
305 |
-
language_issues, annotated_pdf
|
306 |
-
|
|
|
|
|
307 |
except Exception as e:
|
|
|
308 |
return {"error": str(e)}, None
|
309 |
|
310 |
# ------------------------------
|
|
|
291 |
# Main Analysis Function
|
292 |
# ------------------------------
|
293 |
|
294 |
+
# server/gradio_client.py
|
295 |
+
|
296 |
def analyze_pdf(filepath: str) -> Tuple[Dict[str, Any], bytes]:
|
297 |
"""Analyzes the PDF for language issues and returns results and annotated PDF."""
|
298 |
try:
|
|
|
301 |
return {"error": "Failed to extract text from PDF."}, None
|
302 |
|
303 |
language_issues = check_language_issues(full_text)
|
304 |
+
|
305 |
+
# Handle potential errors from check_language_issues
|
306 |
+
if "error" in language_issues:
|
307 |
+
return {"error": language_issues["error"]}, None
|
308 |
+
|
309 |
+
issues = language_issues.get("issues", [])
|
310 |
|
311 |
+
if issues:
|
312 |
+
language_issues, annotated_pdf = highlight_issues_in_pdf(filepath, issues)
|
313 |
+
return {"issues": language_issues}, annotated_pdf
|
314 |
+
else:
|
315 |
+
# Return a meaningful message and no annotated PDF if no issues are found
|
316 |
+
return {"message": "No language issues found in the uploaded PDF."}, None
|
317 |
except Exception as e:
|
318 |
+
# Return the error message and no annotated PDF
|
319 |
return {"error": str(e)}, None
|
320 |
|
321 |
# ------------------------------
|