Skip to content

Commit 23e3291

Browse files
authored
package v1.0.0 (#9)
* model downloader * packaging script. add classifiers to setup.py * minor correction
1 parent ef68509 commit 23e3291

File tree

5 files changed

+91
-5
lines changed

5 files changed

+91
-5
lines changed

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
include README.md
2+
include LICENSE
13
include tdmelodic/nn/lang/mecab/my_mecabrc
24
include tdmelodic/nn/resource/net_it_2500000

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<p align="center">
2-
<img src="imgs/logo/logo_tdmelodic.svg" width="200" />
2+
<img src="https://github.com/PKSHATechnology-Research/tdmelodic/raw/master/imgs/logo/logo_tdmelodic.svg" width="200" />
33
</p>
44

55

packege.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
# remove binary and create dummy file
4+
echo -----------------------------------------------------------
5+
files_to_exclude="
6+
tdmelodic/nn/resource/net_it_2500000
7+
"
8+
9+
for f in $files_to_exclude;
10+
do
11+
echo replace $f with an empty file
12+
if [ -e $f ]; then
13+
mv $f ${f}_bak
14+
fi
15+
touch $f
16+
done
17+
18+
# remove old files
19+
echo -----------------------------------------------------------
20+
echo removing obosolete files
21+
rm -rf dist/*
22+
rm -rf tdmelodic.egg-info*
23+
24+
# sdist
25+
echo -----------------------------------------------------------
26+
python3 setup.py sdist bdist_wheel
27+
28+
# back
29+
echo -----------------------------------------------------------
30+
for f in $files_to_exclude;
31+
do
32+
echo moving ${f}_bak back to $f
33+
mv ${f}_bak ${f}
34+
done
35+
36+
# done
37+
echo -----------------------------------------------------------
38+
echo Done.

setup.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ def _get_version():
2424
author="Hideyuki Tachibana",
2525
author_email='[email protected]',
2626
python_requires='>=3.7',
27+
url="https://github.com/PKSHATechnology-Research/tdmelodic",
2728

2829
description="tdmelodic: Tokyo Japanese Accent Estimator",
2930
long_description=_readme(),
30-
31+
long_description_content_type="text/markdown",
32+
3133
install_requires=_requirements(),
3234
tests_requires=_requirements(),
3335
setup_requires=[],
@@ -44,5 +46,19 @@ def _get_version():
4446
'tdmelodic-neologd-patch = tdmelodic.script.neologd_patch:main',
4547
'tdmelodic-modify-unigram-cost = tdmelodic.script.postprocess_modify_unigram_cost:main',
4648
]
47-
}
49+
},
50+
51+
classifiers=[
52+
'Development Status :: 5 - Production/Stable',
53+
'Environment :: Console',
54+
'Intended Audience :: Science/Research',
55+
'Intended Audience :: Developers',
56+
'License :: OSI Approved :: BSD License',
57+
'Operating System :: POSIX',
58+
'Programming Language :: Python :: 3.7',
59+
'Topic :: Text Processing :: Linguistic',
60+
'Topic :: Multimedia :: Sound/Audio :: Speech',
61+
'Topic :: Scientific/Engineering :: Artificial Intelligence',
62+
'Natural Language :: Japanese',
63+
]
4864
)

tdmelodic/nn/inference.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import numpy as np
1313
from tqdm import tqdm
14+
import urllib.request
1415

1516
import chainer
1617
import chainer.functions as F
@@ -27,13 +28,42 @@
2728
gpu_id = -1 # cpu
2829
bs = 1
2930
embed_dim = 64
30-
_default_path= os.path.dirname(os.path.abspath(__file__)) + "/resource/net_it_2500000"
31+
32+
_github_url = "https://github.com/PKSHATechnology-Research/tdmelodic"
33+
model_location={
34+
"path" : os.path.dirname(os.path.abspath(__file__)) + "/resource/net_it_2500000",
35+
"url" : _github_url + "/raw/master/tdmelodic/nn/resource/net_it_2500000"
36+
}
37+
38+
# ------------------------------------------------------------------------------
39+
class model_downloader(object):
40+
def __init__(self, path, url=model_location["url"]):
41+
self.path = path
42+
self.url = url
43+
if self.__check_if_file_empty(self.path):
44+
self.__download()
45+
else:
46+
self.__already_downloaded()
47+
48+
def __check_if_file_empty(self, path_):
49+
return not os.path.exists(path_) or os.path.getsize(path_) == 0
50+
51+
def __download(self):
52+
print("[ tdmelodic Model Downloader ] Downloading the pretrained model.")
53+
print("[ tdmelodic Model Downloader ] From {}".format(self.url))
54+
print("[ tdmelodic Model Downloader ] To {}".format(self.path))
55+
urllib.request.urlretrieve(self.url, self.path)
56+
print("[ tdmelodic Model Downloader ] Done")
57+
58+
def __already_downloaded(self):
59+
print("[ tdmelodic Model Downloader ] The tdmelodic pretrained model already on your system.")
3160

3261
# ------------------------------------------------------------------------------
3362
class InferAccent(object):
3463
def __init__(self,
35-
model_path=_default_path,
64+
model_path=model_location["path"],
3665
model_dim=embed_dim):
66+
model_downloader(model_path)
3767
self.net = self.__load_model(model_path, model_dim)
3868

3969
def __load_model(self, model_path, model_dim):

0 commit comments

Comments
 (0)