QubitPi commited on
Commit
b0bcb9b
1 Parent(s): 48ed62f

Publish to Hugging Face space

Browse files
Files changed (15) hide show
  1. .dockerignore +16 -0
  2. .gitattributes +35 -0
  3. .github/workflows/ci-cd.yaml +142 -0
  4. .gitignore +5 -1
  5. .lycheeignore +1 -0
  6. .mdlrc +2 -0
  7. .yamllint +23 -0
  8. 1-second-of-silence.mp3 +0 -0
  9. Dockerfile +22 -0
  10. LICENSE +201 -0
  11. README.md +106 -16
  12. app.py +99 -0
  13. convert.py +0 -13
  14. markdownlint.rb +20 -0
  15. requirements.txt +3 -0
.dockerignore ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ __pycache__/
2
+ *.pyc
3
+ *.pyo
4
+ *.pyd
5
+ .venv/
6
+ Pipfile
7
+ Pipfile.lock
8
+ *.pyc
9
+ *.pyo
10
+ *.pyd
11
+ *.egg-info/
12
+ dist/
13
+ build/
14
+ .idea/
15
+ .DS_Store
16
+ .git/
.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
.github/workflows/ci-cd.yaml ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright Jiaqi Liu
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ ---
15
+ name: CI/CD
16
+
17
+ on:
18
+ pull_request:
19
+ push:
20
+ branches: [master]
21
+
22
+ env:
23
+ PYTHON_VERSION: "3.10"
24
+
25
+ jobs:
26
+ cancel-previous:
27
+ name: Cancel Previous Runs In Order to Allocate Action Resources Immediately for Current Run
28
+ if: github.ref != 'refs/heads/master'
29
+ runs-on: ubuntu-latest
30
+ steps:
31
+ - name: Cancel previous
32
+ uses: styfle/cancel-workflow-action@0.10.1
33
+ with:
34
+ access_token: ${{ github.token }}
35
+
36
+ yaml-lint:
37
+ name: YAML Style Check
38
+ runs-on: ubuntu-latest
39
+ steps:
40
+ - uses: actions/checkout@v3
41
+ - uses: actionshub/yamllint@main
42
+
43
+ markdown-lint:
44
+ name: Markdown Style Check
45
+ runs-on: ubuntu-latest
46
+ steps:
47
+ - uses: actions/checkout@v3
48
+ - uses: actionshub/markdownlint@main
49
+
50
+ linkChecker:
51
+ name: Link Check
52
+ runs-on: ubuntu-latest
53
+ steps:
54
+ - uses: actions/checkout@v3
55
+ - name: Link Checker
56
+ uses: lycheeverse/lychee-action@v1.9.0
57
+ with:
58
+ fail: true
59
+
60
+ integration-tests:
61
+ name: Integration Tests
62
+ needs: [yaml-lint, markdown-lint, linkChecker]
63
+ runs-on: ubuntu-latest
64
+ steps:
65
+ - uses: actions/checkout@v3
66
+ - name: Set up Python ${{ env.PYTHON_VERSION }}
67
+ uses: actions/setup-python@v5
68
+ with:
69
+ python-version: ${{ env.PYTHON_VERSION }}
70
+ - run: pip3 install -r requirements.txt
71
+ - name: Start app
72
+ run: python3 app.py &
73
+ - name: Wait for app to be ready
74
+ uses: iFaxity/wait-on-action@v1
75
+ with:
76
+ resource: http://localhost:7860
77
+ - name: Verify API endpoint is working
78
+ uses: iFaxity/wait-on-action@v1
79
+ with:
80
+ resource: http://localhost:7860/?view=api
81
+ timeout: 60000
82
+
83
+ docker:
84
+ name: Test Docker Image & Container and Publish Image to Docker Hub
85
+ needs: [yaml-lint, markdown-lint, linkChecker]
86
+ runs-on: ubuntu-latest
87
+ steps:
88
+ - uses: actions/checkout@v3
89
+ with:
90
+ fetch-depth: 0
91
+ - name: Set up Python ${{ env.PYTHON_VERSION }}
92
+ uses: actions/setup-python@v4
93
+ with:
94
+ python-version: ${{ env.PYTHON_VERSION }}
95
+ - name: Image Build Test
96
+ run: docker build -t jack20191124/aristotle .
97
+ - name: Startup a Container
98
+ run: docker run -d --name aristotle -p 7860:7860 -e SERVER_NAME=0.0.0.0 jack20191124/aristotle
99
+ - name: Wait for container to be up and running
100
+ uses: iFaxity/wait-on-action@v1
101
+ with:
102
+ resource: http://localhost:7860
103
+ - name: Verify API endpoint is working
104
+ uses: iFaxity/wait-on-action@v1
105
+ with:
106
+ resource: http://localhost:7860/?view=api
107
+ timeout: 60000
108
+ - name: Login to DockerHub
109
+ if: github.ref == 'refs/heads/master'
110
+ uses: docker/login-action@v2
111
+ with:
112
+ username: jack20191124
113
+ password: ${{ secrets.DOCKERHUB_TOKEN }}
114
+ - name: Push image to DockerHub
115
+ if: github.ref == 'refs/heads/master'
116
+ uses: docker/build-push-action@v3
117
+ with:
118
+ context: .
119
+ push: true
120
+ tags: jack20191124/aristotle:latest
121
+ - name: Push image Description
122
+ if: github.ref == 'refs/heads/master'
123
+ uses: peter-evans/dockerhub-description@v4
124
+ with:
125
+ username: jack20191124
126
+ password: ${{ secrets.DOCKERHUB_TOKEN }}
127
+ repository: jack20191124/aristotle
128
+ readme-filepath: README.md
129
+
130
+ sync-to-huggingface-space:
131
+ needs: [integration-tests]
132
+ if: github.ref == 'refs/heads/master'
133
+ runs-on: ubuntu-latest
134
+ steps:
135
+ - uses: actions/checkout@v3
136
+ with:
137
+ fetch-depth: 0
138
+ lfs: true
139
+ - name: Push to hub
140
+ run: git push https://QubitPi:$HF_TOKEN@huggingface.co/spaces/QubitPi/aristotle master:main -f
141
+ env:
142
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
.gitignore CHANGED
@@ -1 +1,5 @@
1
- .idea/
 
 
 
 
 
1
+ .idea
2
+ .env
3
+ venv
4
+ __pycache__
5
+ docker-compose.yml
.lycheeignore ADDED
@@ -0,0 +1 @@
 
 
1
+ http://localhost:7860
.mdlrc ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ rules "~MD002", "~MD003", "~MD005", "~MD007", "~MD013", "~MD022", "~MD024", "~MD027", "~MD028", "~MD029", "~MD033", "~MD034", "~MD036", "~MD041", "~MD055", "~MD057"
2
+ style "#{File.dirname(__FILE__)}/markdownlint.rb"
.yamllint ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ extends: default
3
+ rules:
4
+ line-length:
5
+ max: 256
6
+ level: warning
7
+ document-start: disable
8
+ braces:
9
+ forbid: false
10
+ min-spaces-inside: 0
11
+ max-spaces-inside: 1
12
+ min-spaces-inside-empty: -1
13
+ max-spaces-inside-empty: -1
14
+ commas:
15
+ max-spaces-before: -1
16
+ min-spaces-after: 1
17
+ max-spaces-after: -1
18
+ brackets:
19
+ max-spaces-inside: -1
20
+ empty-lines:
21
+ max: 3
22
+ indentation:
23
+ spaces: 2
1-second-of-silence.mp3 ADDED
Binary file (37.2 kB). View file
 
Dockerfile ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright Jiaqi Liu
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ FROM python:3.10-slim
16
+
17
+ WORKDIR /usr/src/app
18
+ COPY . .
19
+ RUN pip install -r requirements.txt
20
+ EXPOSE 7860
21
+
22
+ CMD ["python", "app.py"]
LICENSE ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2024 Jiaqi Liu
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
README.md CHANGED
@@ -1,11 +1,47 @@
1
- Ancient Greek Reader NLP
2
- ========================
 
 
 
 
 
 
 
 
 
 
3
 
4
- __A lack of audio content is a major hurdle to learning Ancient Greek__. So I decided to tackle this problem with NLP.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  How Does It Work
7
  ----------------
8
 
 
 
 
 
9
  OpenAI will read Ancient Greek text with a modern Greek pronunciation. What's different about OpenAI from other
10
  Text-to-Speech tools is that OpenAI is unaffected by the different accents and breathing marks in Ancient Greek. It will
11
  simply read the Ancient Greek text in modern pronunciation with the accents in the right places. Studying Ancient Greeek
@@ -28,22 +64,76 @@ And here is the same but with letters replaced to try and get OpenAI to read in
28
  A huge list of [letter replacements](./ancient-greek-phonemes.txt) has been made to try and imitate Attic pronunciation
29
  as closely as possible. The result is pretty solid and is close enough to be useful for creating audio files for texts
30
  where we don't have any audio recordings.
31
- [Checkout this "Attic" pronounciation example](https://qubitpi.github.io/ancient-greek-reader/)
32
 
33
- How to Use It (WIP)
34
- -------------------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
- Here is a __WIP__ instruction:
 
37
 
38
- 1. Get an accurate Ancient Greek text and save it to a file named __original.txt__.
39
- [Perseus Digital Library](https://www.perseus.tufts.edu/hopper/) is a great source.
40
- 2. Run replacement:
41
 
42
- - `python3 convert.py`
 
43
 
44
- 3. Convert txt to epub. [Calibre](https://calibre-ebook.com/) works pretty well for this.
45
- 4. Use https://github.com/p0n1/epub_to_audiobook to generate audio
 
 
46
 
47
- > [!CAUTION]
48
- >
49
- > OpenAI [billing](https://platform.openai.com/settings/organization/billing/overview) will apply to the last step
 
1
+ ---
2
+ title: Aristotle
3
+ emoji: 🏆
4
+ colorFrom: gray
5
+ colorTo: green
6
+ sdk: gradio
7
+ sdk_version: 5.1.0
8
+ app_file: app.py
9
+ pinned: false
10
+ license: apache-2.0
11
+ short_description: Ancient Greek text to audio
12
+ ---
13
 
14
+ Aristotle
15
+ =========
16
+
17
+ ![Python Version Badge]
18
+ [![Hugging Face space badge]][Hugging Face space URL]
19
+ [![GitHub workflow status badge][GitHub workflow status badge]][GitHub workflow status URL]
20
+ [![Hugging Face sync status badge]][Hugging Face sync status URL]
21
+ [![Docker Hub][Docker Pulls Badge]][Docker Hub URL]
22
+ [![Apache License Badge]][Apache License, Version 2.0]
23
+
24
+ __Aristotle__ is an automatic text to speech application that takes an Ancient Greek excerpt as input and generates a
25
+ downloadable audio for language learner for practice speaking in Ancient Greek. Aristotle generates speech using the
26
+ [OpenAI's text-to-speech API](https://platform.openai.com/docs/guides/text-to-speech).
27
+
28
+ The app is available on [Hugging Face space][Project Aristotle on Hugging Face]. Please check it out.
29
+
30
+ A Docker image is also available:
31
+
32
+ ```console
33
+ docker run -d --name aristotle -p 7860:7860 jack20191124/aristotle
34
+ ```
35
+
36
+ When container is up and running, visit app at [http://localhost:7860](http://localhost:7860).
37
 
38
  How Does It Work
39
  ----------------
40
 
41
+ Ancient Greek is a phonetically-lost language, because no one knows the correct pronunciation of such an ancient
42
+ language. __A lack of audio content is a major hurdle to learning Ancient Greek__. So I decided to tackle this problem
43
+ with NLP.
44
+
45
  OpenAI will read Ancient Greek text with a modern Greek pronunciation. What's different about OpenAI from other
46
  Text-to-Speech tools is that OpenAI is unaffected by the different accents and breathing marks in Ancient Greek. It will
47
  simply read the Ancient Greek text in modern pronunciation with the accents in the right places. Studying Ancient Greeek
 
64
  A huge list of [letter replacements](./ancient-greek-phonemes.txt) has been made to try and imitate Attic pronunciation
65
  as closely as possible. The result is pretty solid and is close enough to be useful for creating audio files for texts
66
  where we don't have any audio recordings.
 
67
 
68
+ Development
69
+ -----------
70
+
71
+ ### Running Locally
72
+
73
+ ```console
74
+ git clone git@github.com:QubitPi/aristotle.git
75
+ cd aristotle
76
+
77
+ virtualenv .venv
78
+ source .venv/bin/activate
79
+ pip3 install -r requirements.txt
80
+ ```
81
+
82
+ To start the app:
83
+
84
+ ```console
85
+ export SERVER_NAME=127.0.0.1
86
+ python3 app.py
87
+ ```
88
+
89
+ The app will be available at [http://localhost:7860](http://localhost:7860) and the API docs at
90
+ [http://localhost:7860/?view=api](http://localhost:7860/?view=api)
91
+
92
+ ### Docker
93
+
94
+ To build a Docker container of Aristotle, follow these steps:
95
+
96
+ 1. Make sure Docker has been installed
97
+ 2. Open a terminal and navigate to the project directory.
98
+ 3. Run the following command to build the Docker image:
99
+
100
+ ```consule
101
+ docker build -t jack20191124/aristotle .
102
+ ```
103
+
104
+ 4. Wait for the build process to complete.
105
+ 5. Once the build is finished, we can run the Docker container using the following command:
106
+
107
+ ```console
108
+ docker run -it --name aristotle -p 7860:7860 jack20191124/aristotle
109
+ ```
110
+
111
+ 6. Open up browser and navigate to [http://localhost:7860](http://localhost:7860) to access the space.
112
+
113
+ ### Toubleshooting
114
+
115
+ #### `No matching distribution found for fastapi` While Executing `pip3 install -r requirements.txt`
116
+
117
+ This could be caused by one's proxy. Simply turn-off or switch proxy should work
118
+
119
+ License
120
+ -------
121
+
122
+ The use and distribution terms for [aristotle]() are covered by the [Apache License, Version 2.0].
123
 
124
+ [Apache License Badge]: https://img.shields.io/badge/Apache%202.0-F25910.svg?style=for-the-badge&logo=Apache&logoColor=white
125
+ [Apache License, Version 2.0]: https://www.apache.org/licenses/LICENSE-2.0
126
 
127
+ [Docker Pulls Badge]: https://img.shields.io/docker/pulls/jack20191124/aristotle?style=for-the-badge&logo=docker&color=2596EC
128
+ [Docker Hub URL]: https://hub.docker.com/r/jack20191124/aristotle
 
129
 
130
+ [GitHub workflow status badge]: https://img.shields.io/github/actions/workflow/status/QubitPi/wilhelm/ci-cd.yaml?branch=master&style=for-the-badge&logo=github&logoColor=white&label=CI/CD
131
+ [GitHub workflow status URL]: https://github.com/QubitPi/wilhelm/actions/workflows/ci-cd.yaml
132
 
133
+ [Hugging Face space badge]: https://img.shields.io/badge/Hugging%20Face%20Space-aristotle-FFD21E?style=for-the-badge&logo=huggingface&logoColor=white
134
+ [Hugging Face space URL]: https://huggingface.co/spaces/QubitPi/aristotle
135
+ [Hugging Face sync status badge]: https://img.shields.io/github/actions/workflow/status/QubitPi/aristotle/ci-cd.yaml?branch=master&style=for-the-badge&logo=github&logoColor=white&label=Hugging%20Face%20Sync%20Up
136
+ [Hugging Face sync status URL]: https://github.com/QubitPi/aristotle/actions/workflows/ci-cd.yaml
137
 
138
+ [Project Aristotle on Hugging Face]: https://huggingface.co/spaces/QubitPi/aristotle
139
+ [Python Version Badge]: https://img.shields.io/badge/Python-3.10-FFD845?labelColor=498ABC&style=for-the-badge&logo=python&logoColor=white
 
app.py ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright Jiaqi Liu
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ import os
15
+ import tempfile
16
+ from typing import Literal
17
+ from typing import Union
18
+
19
+ import gradio as gr
20
+ from openai import OpenAI
21
+
22
+ server_name = os.getenv("SERVER_NAME", "0.0.0.0")
23
+
24
+ def latin_replacement(text: str):
25
+ with open("ancient-greek-phonemes.txt", "r") as mapping_file:
26
+ mapping = dict(
27
+ [(ancient_greek, latin) for ancient_greek, latin in
28
+ [line.rstrip().split("->") for line in mapping_file.readlines()]]
29
+ )
30
+ for key, value in mapping.items():
31
+ text = text.replace(key, value)
32
+
33
+ return text
34
+
35
+
36
+ def tts(
37
+ openai_key: str,
38
+ text: str,
39
+ model: Union[str, Literal["tts-1", "tts-1-hd"]],
40
+ voice: Literal["alloy", "echo", "fable", "onyx", "nova", "shimmer"],
41
+ output_file_format: Literal["mp3", "opus", "aac", "flac"] = "mp3",
42
+ speed: float = 1.0
43
+ ):
44
+ if len(text) > 0:
45
+ text = latin_replacement(text)
46
+
47
+ try:
48
+ client = OpenAI(api_key=openai_key)
49
+
50
+ response = client.audio.speech.create(
51
+ model=model,
52
+ voice=voice,
53
+ input=text,
54
+ response_format=output_file_format,
55
+ speed=speed
56
+ )
57
+
58
+ except Exception as error:
59
+ print(str(error))
60
+ raise gr.Error(
61
+ "An error occurred while generating speech. Please check your API key and come back try again.")
62
+
63
+ with tempfile.NamedTemporaryFile(suffix=".mp3", delete=False) as temp_file:
64
+ temp_file.write(response.content)
65
+
66
+ temp_file_path = temp_file.name
67
+
68
+ return temp_file_path
69
+ else:
70
+ return "1-second-of-silence.mp3"
71
+
72
+
73
+ with gr.Blocks() as app:
74
+ gr.Markdown("# <center> AI Doesn't Speak Ancient Greek. Aristotle Does! </center>")
75
+ with gr.Row(variant="panel"):
76
+ model = gr.Dropdown(choices=["tts-1", "tts-1-hd"], label="Model", value="tts-1")
77
+ voice = gr.Dropdown(choices=["alloy", "echo", "fable", "onyx", "nova", "shimmer"], label="Voice Options",
78
+ value="alloy")
79
+ output_file_format = gr.Dropdown(choices=["mp3", "opus", "aac", "flac"], label="Output Options", value="mp3")
80
+ speed = gr.Slider(minimum=0.25, maximum=4.0, value=1.0, step=0.01, label="Speed")
81
+
82
+ openai_key = gr.Textbox(
83
+ label="OpenAI API key",
84
+ placeholder="We can get the key at https://platform.openai.com/api-keys"
85
+ )
86
+ text = gr.Textbox(
87
+ label="Ancient Greek text",
88
+ placeholder="Enter your text and then click on the \"Text-To-Speech\" button, or simply press the Enter key."
89
+ )
90
+ examples = gr.Examples([[" Ὁμώνυμα λέγεται ὧν ὄνομα μόνον κοινόν"]], text)
91
+ btn = gr.Button("Hear It!")
92
+ output_audio = gr.Audio(label="Speech Output")
93
+
94
+ text.submit(fn=tts, inputs=[openai_key, text, model, voice, output_file_format, speed], outputs=output_audio,
95
+ api_name="tts")
96
+ btn.click(fn=tts, inputs=[openai_key, text, model, voice, output_file_format, speed], outputs=output_audio,
97
+ api_name=False)
98
+
99
+ app.launch(server_name=server_name)
convert.py DELETED
@@ -1,13 +0,0 @@
1
- if __name__ == "__main__":
2
- with open("ancient-greek-phonemes.txt", "r") as mapping_file:
3
- mapping = dict(
4
- [(ancient_greek, latin) for ancient_greek, latin in [line.rstrip().split("->") for line in mapping_file.readlines()]]
5
- )
6
- with open("original.txt", "r") as book_txt:
7
- book = book_txt.read()
8
-
9
- for key, value in mapping.items():
10
- book = book.replace(key, value)
11
-
12
- with open("converted.txt", "w") as book_txt:
13
- book_txt.write(book)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
markdownlint.rb ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright Jiaqi Liu
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ all
16
+ rule 'MD003', style: :setext_with_atx
17
+ rule 'MD004', style: :sublist
18
+ rule 'MD013', line_length: 120
19
+ rule 'MD029', style: :ordered
20
+ rule 'MD026', punctuation: ".,;:!?"
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio~=4.12.0
2
+ openai~=1.2.3
3
+ fastapi==0.112.2