Spaces:
Sleeping
Sleeping
samyak152002
commited on
Commit
β’
a04c0d5
1
Parent(s):
5bb5a7d
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,13 @@
|
|
1 |
import gradio as gr
|
2 |
from annotations import analyze_pdf
|
3 |
-
import base64
|
4 |
import io
|
5 |
|
6 |
def process_pdf(file):
|
|
|
7 |
if file is None:
|
8 |
return "β No file uploaded.", None
|
|
|
|
|
9 |
|
10 |
try:
|
11 |
# Wrap the binary data in BytesIO to make it file-like
|
@@ -18,27 +20,33 @@ def process_pdf(file):
|
|
18 |
return f"β Error: {issues['error']}", None
|
19 |
|
20 |
# Prepare issues for display
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
issues_display
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
31 |
|
32 |
# Prepare annotated PDF for download
|
33 |
if annotated_pdf:
|
34 |
-
#
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
|
|
39 |
else:
|
40 |
return issues_display, None
|
41 |
|
|
|
|
|
42 |
except Exception as e:
|
43 |
return f"β An unexpected error occurred: {str(e)}", None
|
44 |
|
|
|
1 |
import gradio as gr
|
2 |
from annotations import analyze_pdf
|
|
|
3 |
import io
|
4 |
|
5 |
def process_pdf(file):
|
6 |
+
MAX_SIZE = 10 * 1024 * 1024 # 10MB
|
7 |
if file is None:
|
8 |
return "β No file uploaded.", None
|
9 |
+
if len(file) > MAX_SIZE:
|
10 |
+
return "β File size exceeds the 10MB limit.", None
|
11 |
|
12 |
try:
|
13 |
# Wrap the binary data in BytesIO to make it file-like
|
|
|
20 |
return f"β Error: {issues['error']}", None
|
21 |
|
22 |
# Prepare issues for display
|
23 |
+
if issues['total_issues'] == 0:
|
24 |
+
issues_display = "β
No language issues found. Great job!"
|
25 |
+
else:
|
26 |
+
issues_display = f"**Total Issues Found:** {issues['total_issues']}\n\n"
|
27 |
+
for idx, issue in enumerate(issues['issues'], start=1):
|
28 |
+
issues_display += f"**Issue {idx}:**\n"
|
29 |
+
issues_display += f"- **Message:** {issue['message']}\n"
|
30 |
+
issues_display += f"- **Context:** {issue['context']}\n"
|
31 |
+
issues_display += f"- **Suggestions:** {', '.join(issue['suggestions']) if issue['suggestions'] else 'None'}\n"
|
32 |
+
issues_display += f"- **Category:** {issue['category']}\n"
|
33 |
+
issues_display += f"- **Rule ID:** {issue['rule_id']}\n"
|
34 |
+
issues_display += f"- **Offset:** {issue['offset']}\n"
|
35 |
+
issues_display += f"- **Length:** {issue['length']}\n\n"
|
36 |
|
37 |
# Prepare annotated PDF for download
|
38 |
if annotated_pdf:
|
39 |
+
# Return a dictionary with 'name' and 'data' keys
|
40 |
+
annotated_pdf_dict = {
|
41 |
+
"name": "annotated_document.pdf",
|
42 |
+
"data": annotated_pdf
|
43 |
+
}
|
44 |
+
return issues_display, annotated_pdf_dict
|
45 |
else:
|
46 |
return issues_display, None
|
47 |
|
48 |
+
except language_tool_python.LanguageToolError as e:
|
49 |
+
return f"β LanguageTool Error: {str(e)}", None
|
50 |
except Exception as e:
|
51 |
return f"β An unexpected error occurred: {str(e)}", None
|
52 |
|