Commit
·
9282835
1
Parent(s):
e2ab6c9
Fixed cache directory permissions for language tool
Browse files- HTR/spell_and_gramer_check.py +8 -1
- main.py +6 -3
HTR/spell_and_gramer_check.py
CHANGED
@@ -1,7 +1,14 @@
|
|
|
|
1 |
import language_tool_python
|
|
|
2 |
from spellchecker import SpellChecker
|
3 |
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
def check_grammar(answer):
|
7 |
|
|
|
1 |
+
import os
|
2 |
import language_tool_python
|
3 |
+
from pathlib import Path
|
4 |
from spellchecker import SpellChecker
|
5 |
|
6 |
+
# Use the cache directory from environment variable
|
7 |
+
cache_dir = os.getenv('LANGUAGE_TOOL_CACHE_DIR', '/tmp/language_tool')
|
8 |
+
os.makedirs(cache_dir, exist_ok=True)
|
9 |
+
|
10 |
+
# Initialize LanguageTool with the cache directory
|
11 |
+
tool = language_tool_python.LanguageTool('en-US', cache_dir=cache_dir)
|
12 |
|
13 |
def check_grammar(answer):
|
14 |
|
main.py
CHANGED
@@ -1,9 +1,12 @@
|
|
1 |
import os
|
2 |
import tempfile
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
-
os.environ['
|
|
|
|
|
|
|
7 |
|
8 |
from flask import Flask, request, jsonify, render_template
|
9 |
import json
|
|
|
1 |
import os
|
2 |
import tempfile
|
3 |
|
4 |
+
# Create a writable cache directory in /tmp
|
5 |
+
cache_dir = tempfile.mkdtemp()
|
6 |
+
os.environ['TRANSFORMERS_CACHE'] = cache_dir
|
7 |
+
os.environ['HF_HOME'] = cache_dir
|
8 |
+
# Set language tool cache directory
|
9 |
+
os.environ['LANGUAGE_TOOL_CACHE_DIR'] = cache_dir
|
10 |
|
11 |
from flask import Flask, request, jsonify, render_template
|
12 |
import json
|