freemt commited on
Commit
94e5748
·
2 Parent(s): 3d7a5a6 db4ac2b
.gitattributes ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ftz filter=lfs diff=lfs merge=lfs -text
6
+ *.gz filter=lfs diff=lfs merge=lfs -text
7
+ *.h5 filter=lfs diff=lfs merge=lfs -text
8
+ *.joblib filter=lfs diff=lfs merge=lfs -text
9
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
10
+ *.model filter=lfs diff=lfs merge=lfs -text
11
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
12
+ *.onnx filter=lfs diff=lfs merge=lfs -text
13
+ *.ot filter=lfs diff=lfs merge=lfs -text
14
+ *.parquet filter=lfs diff=lfs merge=lfs -text
15
+ *.pb filter=lfs diff=lfs merge=lfs -text
16
+ *.pt filter=lfs diff=lfs merge=lfs -text
17
+ *.pth filter=lfs diff=lfs merge=lfs -text
18
+ *.rar filter=lfs diff=lfs merge=lfs -text
19
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
20
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
21
+ *.tflite filter=lfs diff=lfs merge=lfs -text
22
+ *.tgz filter=lfs diff=lfs merge=lfs -text
23
+ *.wasm filter=lfs diff=lfs merge=lfs -text
24
+ *.xz filter=lfs diff=lfs merge=lfs -text
25
+ *.zip filter=lfs diff=lfs merge=lfs -text
26
+ *.zstandard filter=lfs diff=lfs merge=lfs -text
27
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,18 +1,13 @@
1
- # gradio-ttw-api
2
- [![pytest](https://github.com/ffreemt/gradio-ttw-api/actions/workflows/routine-tests.yml/badge.svg)](https://github.com/ffreemt/gradio-ttw-api/actions)[![python](https://img.shields.io/static/v1?label=python+&message=3.8%2B&color=blue)](https://www.python.org/downloads/)[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)[![PyPI version](https://badge.fury.io/py/gradio_ttw_api.svg)](https://badge.fury.io/py/gradio_ttw_api)
3
-
4
- gradio-ttw-api descr
5
-
6
- ## Install it
7
-
8
- ```shell
9
- pip install git+https://github.com/ffreemt/gradio-ttw-api
10
- # poetry add git+https://github.com/ffreemt/gradio-ttw-api
11
- # git clone https://github.com/ffreemt/gradio-ttw-api && cd gradio-ttw-api
12
- ```
13
-
14
- ## Use it
15
- ```python
16
- from gradio_ttw_api import gradio_ttw_api
17
-
18
- ```
 
1
+ ---
2
+ title: Gradio Ttw Api
3
+ emoji: 🌍
4
+ colorFrom: green
5
+ colorTo: pink
6
+ sdk: gradio
7
+ sdk_version: 3.0.26
8
+ app_file: app.py
9
+ pinned: false
10
+ license: mit
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
gradio_ttw_api/HIT-同义词词林0.txt ADDED
The diff for this file is too large to render. See raw diff
 
gradio_ttw_api/__init__.py CHANGED
@@ -1,4 +1,7 @@
1
- """Init."""
 
 
 
2
  __version__ = "0.1.0a0"
3
  from .gradio_ttw_api import gradio_ttw_api
4
 
 
1
+ """Init.
2
+
3
+ Refer to root@acone3a:~/acone3-old/acone2-dir...websockets-dir
4
+ """
5
  __version__ = "0.1.0a0"
6
  from .gradio_ttw_api import gradio_ttw_api
7
 
gradio_ttw_api/detect_chinese.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Detcet chinese.
2
+
3
+ True if containing any of [一-﨩]
4
+ '\u4e00' <= char <= '\u9fff', False otherwise
5
+ """
6
+
7
+
8
+ def detect_chinese(text):
9
+ """Detcet chinese.
10
+
11
+ Args:
12
+ text: string
13
+
14
+ True if containing any of [一-﨩], False otherwise
15
+ '\u4e00' <= char <= '\u9fff', False otherwise
16
+
17
+ if punctuation needs to be considered:
18
+ from zhon.hanzi import punctuation
19
+ '\u4e00' <= char <= '\u9fff' or char in punctuation
20
+ """
21
+ return any("\u4e00" <= char <= "\u9fff" for char in str(text))
gradio_ttw_api/hit.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Refer to hit_syn.py.
2
+
3
+ https://github.com/RonenNess/grepfunc
4
+ from grepfunc import grep
5
+ """
6
+ # pylint: disable=invalid-name
7
+ from pathlib import Path
8
+ import re
9
+
10
+ # from colorama import init, Fore, Back
11
+ from gradio_ttw_api.detect_chinese import detect_chinese
12
+
13
+ DIRPATH = Path(__file__).parent
14
+
15
+ # rsync -uvaz acone3a:misc/reference-it-terms/HIT-同义词词林0.txt gradio_ttw_api
16
+ FILE1 = r"HIT-同义词词林0.txt"
17
+ FILE2 = r"HIT-IRLab-同义词词林detailed_table_of_contents.txt"
18
+ dict_file = Path(DIRPATH) / Path(FILE1)
19
+
20
+ assert dict_file.is_file(), f" {dict_file} does not exit."
21
+
22
+ # init() # colorama
23
+
24
+
25
+ # def hit_syno(query):
26
+ def hit(query: str):
27
+ """Grep synonyms from HIT synonyms file.
28
+
29
+ >>> query = '同义'
30
+ >>> '均等' in hit(query)
31
+ True
32
+ >>> hit('')
33
+ ''
34
+ """
35
+ if not detect_chinese(query):
36
+ return ""
37
+
38
+ result = []
39
+ with dict_file.open(encoding="utf-8") as fhandle:
40
+ for line in fhandle:
41
+ if query in line:
42
+ result.append(
43
+ re.sub(
44
+ rf"({query})",
45
+ # Fore.RED + r'\1' + Fore.RESET, line
46
+ r"<em>\1</em>",
47
+ line,
48
+ ).strip()
49
+ )
50
+
51
+ return "\n".join(result)