yqkcn
commited on
Commit
·
3d5f9ea
1
Parent(s):
5720dea
remove unused import (#2679)
Browse files### What problem does this PR solve?
### Type of change
- [x] Refactoring
- rag/app/audio.py +0 -2
- rag/app/book.py +3 -3
- rag/app/laws.py +2 -3
- rag/app/manual.py +3 -3
- rag/app/naive.py +2 -3
- rag/app/paper.py +0 -3
- rag/app/qa.py +0 -1
rag/app/audio.py
CHANGED
|
@@ -10,9 +10,7 @@
|
|
| 10 |
# See the License for the specific language governing permissions and
|
| 11 |
# limitations under the License.
|
| 12 |
#
|
| 13 |
-
import io
|
| 14 |
import re
|
| 15 |
-
import numpy as np
|
| 16 |
|
| 17 |
from api.db import LLMType
|
| 18 |
from rag.nlp import rag_tokenizer
|
|
|
|
| 10 |
# See the License for the specific language governing permissions and
|
| 11 |
# limitations under the License.
|
| 12 |
#
|
|
|
|
| 13 |
import re
|
|
|
|
| 14 |
|
| 15 |
from api.db import LLMType
|
| 16 |
from rag.nlp import rag_tokenizer
|
rag/app/book.py
CHANGED
|
@@ -15,9 +15,9 @@ import re
|
|
| 15 |
from io import BytesIO
|
| 16 |
|
| 17 |
from deepdoc.parser.utils import get_text
|
| 18 |
-
from rag.nlp import bullets_category, is_english,
|
| 19 |
-
hierarchical_merge, make_colon_as_title, naive_merge, random_choices, tokenize_table,
|
| 20 |
-
tokenize_chunks
|
| 21 |
from rag.nlp import rag_tokenizer
|
| 22 |
from deepdoc.parser import PdfParser, DocxParser, PlainParser, HtmlParser
|
| 23 |
|
|
|
|
| 15 |
from io import BytesIO
|
| 16 |
|
| 17 |
from deepdoc.parser.utils import get_text
|
| 18 |
+
from rag.nlp import bullets_category, is_english,remove_contents_table, \
|
| 19 |
+
hierarchical_merge, make_colon_as_title, naive_merge, random_choices, tokenize_table, \
|
| 20 |
+
tokenize_chunks
|
| 21 |
from rag.nlp import rag_tokenizer
|
| 22 |
from deepdoc.parser import PdfParser, DocxParser, PlainParser, HtmlParser
|
| 23 |
|
rag/app/laws.py
CHANGED
|
@@ -10,7 +10,6 @@
|
|
| 10 |
# See the License for the specific language governing permissions and
|
| 11 |
# limitations under the License.
|
| 12 |
#
|
| 13 |
-
import copy
|
| 14 |
from tika import parser
|
| 15 |
import re
|
| 16 |
from io import BytesIO
|
|
@@ -18,8 +17,8 @@ from docx import Document
|
|
| 18 |
|
| 19 |
from api.db import ParserType
|
| 20 |
from deepdoc.parser.utils import get_text
|
| 21 |
-
from rag.nlp import bullets_category,
|
| 22 |
-
make_colon_as_title,
|
| 23 |
from rag.nlp import rag_tokenizer
|
| 24 |
from deepdoc.parser import PdfParser, DocxParser, PlainParser, HtmlParser
|
| 25 |
from rag.settings import cron_logger
|
|
|
|
| 10 |
# See the License for the specific language governing permissions and
|
| 11 |
# limitations under the License.
|
| 12 |
#
|
|
|
|
| 13 |
from tika import parser
|
| 14 |
import re
|
| 15 |
from io import BytesIO
|
|
|
|
| 17 |
|
| 18 |
from api.db import ParserType
|
| 19 |
from deepdoc.parser.utils import get_text
|
| 20 |
+
from rag.nlp import bullets_category, remove_contents_table, hierarchical_merge, \
|
| 21 |
+
make_colon_as_title, tokenize_chunks, docx_question_level
|
| 22 |
from rag.nlp import rag_tokenizer
|
| 23 |
from deepdoc.parser import PdfParser, DocxParser, PlainParser, HtmlParser
|
| 24 |
from rag.settings import cron_logger
|
rag/app/manual.py
CHANGED
|
@@ -19,13 +19,13 @@ import re
|
|
| 19 |
|
| 20 |
from api.db import ParserType
|
| 21 |
from io import BytesIO
|
| 22 |
-
from rag.nlp import rag_tokenizer, tokenize, tokenize_table,
|
| 23 |
-
from deepdoc.parser import PdfParser, PlainParser
|
| 24 |
from rag.utils import num_tokens_from_string
|
| 25 |
-
from deepdoc.parser import PdfParser,
|
| 26 |
from docx import Document
|
| 27 |
from PIL import Image
|
| 28 |
|
|
|
|
| 29 |
class Pdf(PdfParser):
|
| 30 |
def __init__(self):
|
| 31 |
self.model_speciess = ParserType.MANUAL.value
|
|
|
|
| 19 |
|
| 20 |
from api.db import ParserType
|
| 21 |
from io import BytesIO
|
| 22 |
+
from rag.nlp import rag_tokenizer, tokenize, tokenize_table, bullets_category, title_frequency, tokenize_chunks, docx_question_level
|
|
|
|
| 23 |
from rag.utils import num_tokens_from_string
|
| 24 |
+
from deepdoc.parser import PdfParser, PlainParser, DocxParser
|
| 25 |
from docx import Document
|
| 26 |
from PIL import Image
|
| 27 |
|
| 28 |
+
|
| 29 |
class Pdf(PdfParser):
|
| 30 |
def __init__(self):
|
| 31 |
self.model_speciess = ParserType.MANUAL.value
|
rag/app/naive.py
CHANGED
|
@@ -25,6 +25,7 @@ from functools import reduce
|
|
| 25 |
from markdown import markdown
|
| 26 |
from docx.image.exceptions import UnrecognizedImageError
|
| 27 |
|
|
|
|
| 28 |
class Docx(DocxParser):
|
| 29 |
def __init__(self):
|
| 30 |
pass
|
|
@@ -93,7 +94,7 @@ class Docx(DocxParser):
|
|
| 93 |
|
| 94 |
tbls = []
|
| 95 |
for tb in self.doc.tables:
|
| 96 |
-
html= "<table>"
|
| 97 |
for r in tb.rows:
|
| 98 |
html += "<tr>"
|
| 99 |
i = 0
|
|
@@ -146,8 +147,6 @@ class Pdf(PdfParser):
|
|
| 146 |
|
| 147 |
class Markdown(MarkdownParser):
|
| 148 |
def __call__(self, filename, binary=None):
|
| 149 |
-
txt = ""
|
| 150 |
-
tbls = []
|
| 151 |
if binary:
|
| 152 |
encoding = find_codec(binary)
|
| 153 |
txt = binary.decode(encoding, errors="ignore")
|
|
|
|
| 25 |
from markdown import markdown
|
| 26 |
from docx.image.exceptions import UnrecognizedImageError
|
| 27 |
|
| 28 |
+
|
| 29 |
class Docx(DocxParser):
|
| 30 |
def __init__(self):
|
| 31 |
pass
|
|
|
|
| 94 |
|
| 95 |
tbls = []
|
| 96 |
for tb in self.doc.tables:
|
| 97 |
+
html = "<table>"
|
| 98 |
for r in tb.rows:
|
| 99 |
html += "<tr>"
|
| 100 |
i = 0
|
|
|
|
| 147 |
|
| 148 |
class Markdown(MarkdownParser):
|
| 149 |
def __call__(self, filename, binary=None):
|
|
|
|
|
|
|
| 150 |
if binary:
|
| 151 |
encoding = find_codec(binary)
|
| 152 |
txt = binary.decode(encoding, errors="ignore")
|
rag/app/paper.py
CHANGED
|
@@ -12,13 +12,11 @@
|
|
| 12 |
#
|
| 13 |
import copy
|
| 14 |
import re
|
| 15 |
-
from collections import Counter
|
| 16 |
|
| 17 |
from api.db import ParserType
|
| 18 |
from rag.nlp import rag_tokenizer, tokenize, tokenize_table, add_positions, bullets_category, title_frequency, tokenize_chunks
|
| 19 |
from deepdoc.parser import PdfParser, PlainParser
|
| 20 |
import numpy as np
|
| 21 |
-
from rag.utils import num_tokens_from_string
|
| 22 |
|
| 23 |
|
| 24 |
class Pdf(PdfParser):
|
|
@@ -135,7 +133,6 @@ def chunk(filename, binary=None, from_page=0, to_page=100000,
|
|
| 135 |
Only pdf is supported.
|
| 136 |
The abstract of the paper will be sliced as an entire chunk, and will not be sliced partly.
|
| 137 |
"""
|
| 138 |
-
pdf_parser = None
|
| 139 |
if re.search(r"\.pdf$", filename, re.IGNORECASE):
|
| 140 |
if not kwargs.get("parser_config", {}).get("layout_recognize", True):
|
| 141 |
pdf_parser = PlainParser()
|
|
|
|
| 12 |
#
|
| 13 |
import copy
|
| 14 |
import re
|
|
|
|
| 15 |
|
| 16 |
from api.db import ParserType
|
| 17 |
from rag.nlp import rag_tokenizer, tokenize, tokenize_table, add_positions, bullets_category, title_frequency, tokenize_chunks
|
| 18 |
from deepdoc.parser import PdfParser, PlainParser
|
| 19 |
import numpy as np
|
|
|
|
| 20 |
|
| 21 |
|
| 22 |
class Pdf(PdfParser):
|
|
|
|
| 133 |
Only pdf is supported.
|
| 134 |
The abstract of the paper will be sliced as an entire chunk, and will not be sliced partly.
|
| 135 |
"""
|
|
|
|
| 136 |
if re.search(r"\.pdf$", filename, re.IGNORECASE):
|
| 137 |
if not kwargs.get("parser_config", {}).get("layout_recognize", True):
|
| 138 |
pdf_parser = PlainParser()
|
rag/app/qa.py
CHANGED
|
@@ -14,7 +14,6 @@ import re
|
|
| 14 |
from copy import deepcopy
|
| 15 |
from io import BytesIO
|
| 16 |
from timeit import default_timer as timer
|
| 17 |
-
from nltk import word_tokenize
|
| 18 |
from openpyxl import load_workbook
|
| 19 |
|
| 20 |
from deepdoc.parser.utils import get_text
|
|
|
|
| 14 |
from copy import deepcopy
|
| 15 |
from io import BytesIO
|
| 16 |
from timeit import default_timer as timer
|
|
|
|
| 17 |
from openpyxl import load_workbook
|
| 18 |
|
| 19 |
from deepdoc.parser.utils import get_text
|