StevenLe456 commited on
Commit
f28a05f
·
1 Parent(s): fd1cc3f

Changed to a Flask app

Browse files
Files changed (3) hide show
  1. README.md +1 -1
  2. app.py +56 -13
  3. requirements.txt +7 -41
README.md CHANGED
@@ -3,7 +3,7 @@ title: Lotus
3
  emoji: 🪷
4
  colorFrom: purple
5
  colorTo: green
6
- sdk: gradio
7
  sdk_version: 3.39.0
8
  app_file: app.py
9
  pinned: false
 
3
  emoji: 🪷
4
  colorFrom: purple
5
  colorTo: green
6
+ sdk: docker
7
  sdk_version: 3.39.0
8
  app_file: app.py
9
  pinned: false
app.py CHANGED
@@ -1,20 +1,63 @@
1
- import gradio as gr
2
  from librosa.feature import mfcc
3
  import numpy as np
4
  from scipy.io.wavfile import read
5
  from tsai.all import *
 
6
 
7
- tone = load_minirocket("minirocket-tone-8981")
8
- vowel = load_minirocket("minirocket-vowel-9814")
 
9
 
10
- def classify(audio):
11
- sr, data = audio
12
- arr = data.astype(float)
13
- m = mfcc(y=arr, sr=sr)
14
- t = tone.predict(m).item(0)
15
- v = tone.predict(m).item(0)
16
- return t, v
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
- app = gr.Interface(fn=classify, inputs=gr.Audio(source="microphone"), outputs=["text", "text"])
19
-
20
- app.launch()
 
 
1
+ from flask import Flask, jsonify, request
2
  from librosa.feature import mfcc
3
  import numpy as np
4
  from scipy.io.wavfile import read
5
  from tsai.all import *
6
+ from werkzeug.utils import secure_filename
7
 
8
+ app = Flask(__name__)
9
+ UPLOAD_FOLDER = "./"
10
+ app.config["UPLOAD_FOLDER"] = UPLOAD_FOLDER
11
 
12
+ def preprocess(audio):
13
+ sr, a = audio
14
+ m = mfcc(y=a.astype(float), sr=sr)
15
+ l = []
16
+ for a in m:
17
+ l.append([])
18
+ flag = True
19
+ for b in a:
20
+ if abs(b) < 1e-3 and flag:
21
+ continue
22
+ else:
23
+ flag = False
24
+ l[len(l) - 1].append(b)
25
+ listy = []
26
+ for a in l.reverse():
27
+ listy.insert(0, [])
28
+ for b in a.reverse():
29
+ if abs(b) < 1e-3 and flag:
30
+ continue
31
+ else:
32
+ flag = False
33
+ listy[0].insert(0, b)
34
+ temp = []
35
+ for a in listy:
36
+ if len(a) < 236:
37
+ a.extend([0 for i in range(236 - len(a))])
38
+ temp.append(a)
39
+ elif len(a) > 236:
40
+ c = (len(a) - 236) / 2
41
+ temp.append(a[c : c + 236])
42
+ else:
43
+ temp.append(a)
44
+ m = np.array(temp)
45
+ return m
46
+
47
+ @app.route("/tone-vowel", methods=["POST"])
48
+ def tone_vowel_pred():
49
+ if "blob" in request.files:
50
+ file = request.files["blob"]
51
+ filename = secure_filename(file.filename)
52
+ filepath = os.path.join(app.config["UPLOAD_FOLDER"], filename)
53
+ file.save(filepath)
54
+ audio = read(filepath)
55
+ m = preprocess(audio)
56
+ t = tone.predict(m).item(0)
57
+ v = vowel.predict(m).item(0)
58
+ return jsonify({"vowel": v, "tone": t})
59
 
60
+ if __name__ == "__main__":
61
+ tone = load_minirocket("minirocket-tone-8981")
62
+ vowel = load_minirocket("minirocket-vowel-9814")
63
+ app.run(debug=True)
requirements.txt CHANGED
@@ -1,15 +1,9 @@
1
- aiofiles==23.1.0
2
- aiohttp==3.8.5
3
- aiosignal==1.3.1
4
- altair==5.0.1
5
  annotated-types==0.5.0
6
- anyio==3.7.1
7
  appdirs==1.4.4
8
  asttokens==2.2.1
9
- async-timeout==4.0.2
10
- attrs==23.1.0
11
  audioread==3.0.0
12
  backcall==0.2.0
 
13
  blis==0.7.10
14
  catalogue==2.0.9
15
  certifi==2023.7.22
@@ -25,51 +19,35 @@ cymem==2.0.7
25
  debugpy==1.6.7.post1
26
  decorator==5.1.1
27
  Deprecated==1.2.14
28
- exceptiongroup==1.1.2
29
  executing==1.2.0
30
  fastai==2.7.12
31
- fastapi==0.101.0
32
  fastcore==1.5.29
33
  fastdownload==0.0.7
34
  fastprogress==1.0.3
35
- ffmpy==0.3.1
36
  filelock==3.12.2
 
37
  fonttools==4.42.0
38
- frozenlist==1.4.0
39
- fsspec==2023.6.0
40
- gradio==3.39.0
41
- gradio_client==0.3.0
42
- h11==0.14.0
43
- httpcore==0.17.3
44
- httpx==0.24.1
45
- huggingface-hub==0.16.4
46
  idna==3.4
47
  imbalanced-learn==0.11.0
48
  ipykernel==6.25.1
49
  ipython==8.14.0
 
50
  jedi==0.19.0
51
  Jinja2==3.1.2
52
- joblib==1.3.1
53
- jsonschema==4.19.0
54
- jsonschema-specifications==2023.7.1
55
  jupyter_client==8.3.0
56
  jupyter_core==5.3.1
57
  kiwisolver==1.4.4
58
  langcodes==3.3.0
59
  lazy_loader==0.3
60
  librosa==0.10.0.post2
61
- linkify-it-py==2.0.2
62
  lit==16.0.6
63
  llvmlite==0.40.1
64
- markdown-it-py==2.2.0
65
  MarkupSafe==2.1.3
66
  matplotlib==3.7.2
67
  matplotlib-inline==0.1.6
68
- mdit-py-plugins==0.3.3
69
- mdurl==0.1.2
70
  mpmath==1.3.0
71
  msgpack==1.0.5
72
- multidict==6.0.4
73
  murmurhash==1.0.9
74
  nest-asyncio==1.5.7
75
  networkx==3.1
@@ -86,7 +64,6 @@ nvidia-cusolver-cu11==11.4.0.1
86
  nvidia-cusparse-cu11==11.7.4.91
87
  nvidia-nccl-cu11==2.14.3
88
  nvidia-nvtx-cu11==11.7.91
89
- orjson==3.9.4
90
  packaging==23.1
91
  pandas==2.0.3
92
  parso==0.8.3
@@ -104,26 +81,20 @@ pure-eval==0.2.2
104
  pycparser==2.21
105
  pydantic==2.1.1
106
  pydantic_core==2.4.0
107
- pydub==0.25.1
108
  Pygments==2.16.1
109
  pyparsing==3.0.9
110
  python-dateutil==2.8.2
111
- python-multipart==0.0.6
112
  pyts==0.13.0
113
  pytz==2023.3
114
  PyYAML==6.0.1
115
- pyzmq==25.1.0
116
- referencing==0.30.2
117
  requests==2.31.0
118
- rpds-py==0.9.2
119
  scikit-base==0.5.0
120
  scikit-learn==1.2.2
121
  scipy==1.11.1
122
- semantic-version==2.10.0
123
  six==1.16.0
124
  sktime==0.21.0
125
  smart-open==6.3.0
126
- sniffio==1.3.0
127
  soundfile==0.12.1
128
  soxr==0.3.5
129
  spacy==3.6.1
@@ -131,26 +102,21 @@ spacy-legacy==3.0.12
131
  spacy-loggers==1.0.4
132
  srsly==2.4.7
133
  stack-data==0.6.2
134
- starlette==0.27.0
135
  sympy==1.12
136
  thinc==8.1.11
137
  threadpoolctl==3.2.0
138
- toolz==0.12.0
139
  torch==2.0.1
140
  torchvision==0.15.2
141
  tornado==6.3.2
142
- tqdm==4.65.2
143
  traitlets==5.9.0
144
  triton==2.0.0
145
  tsai==0.3.7
146
  typer==0.9.0
147
  typing_extensions==4.7.1
148
  tzdata==2023.3
149
- uc-micro-py==1.0.2
150
  urllib3==2.0.4
151
- uvicorn==0.23.2
152
  wasabi==1.1.2
153
  wcwidth==0.2.6
154
- websockets==11.0.3
155
  wrapt==1.15.0
156
- yarl==1.9.2
 
 
 
 
 
1
  annotated-types==0.5.0
 
2
  appdirs==1.4.4
3
  asttokens==2.2.1
 
 
4
  audioread==3.0.0
5
  backcall==0.2.0
6
+ blinker==1.6.2
7
  blis==0.7.10
8
  catalogue==2.0.9
9
  certifi==2023.7.22
 
19
  debugpy==1.6.7.post1
20
  decorator==5.1.1
21
  Deprecated==1.2.14
 
22
  executing==1.2.0
23
  fastai==2.7.12
 
24
  fastcore==1.5.29
25
  fastdownload==0.0.7
26
  fastprogress==1.0.3
 
27
  filelock==3.12.2
28
+ Flask==2.3.2
29
  fonttools==4.42.0
 
 
 
 
 
 
 
 
30
  idna==3.4
31
  imbalanced-learn==0.11.0
32
  ipykernel==6.25.1
33
  ipython==8.14.0
34
+ itsdangerous==2.1.2
35
  jedi==0.19.0
36
  Jinja2==3.1.2
37
+ joblib==1.3.2
 
 
38
  jupyter_client==8.3.0
39
  jupyter_core==5.3.1
40
  kiwisolver==1.4.4
41
  langcodes==3.3.0
42
  lazy_loader==0.3
43
  librosa==0.10.0.post2
 
44
  lit==16.0.6
45
  llvmlite==0.40.1
 
46
  MarkupSafe==2.1.3
47
  matplotlib==3.7.2
48
  matplotlib-inline==0.1.6
 
 
49
  mpmath==1.3.0
50
  msgpack==1.0.5
 
51
  murmurhash==1.0.9
52
  nest-asyncio==1.5.7
53
  networkx==3.1
 
64
  nvidia-cusparse-cu11==11.7.4.91
65
  nvidia-nccl-cu11==2.14.3
66
  nvidia-nvtx-cu11==11.7.91
 
67
  packaging==23.1
68
  pandas==2.0.3
69
  parso==0.8.3
 
81
  pycparser==2.21
82
  pydantic==2.1.1
83
  pydantic_core==2.4.0
 
84
  Pygments==2.16.1
85
  pyparsing==3.0.9
86
  python-dateutil==2.8.2
 
87
  pyts==0.13.0
88
  pytz==2023.3
89
  PyYAML==6.0.1
90
+ pyzmq==25.1.1
 
91
  requests==2.31.0
 
92
  scikit-base==0.5.0
93
  scikit-learn==1.2.2
94
  scipy==1.11.1
 
95
  six==1.16.0
96
  sktime==0.21.0
97
  smart-open==6.3.0
 
98
  soundfile==0.12.1
99
  soxr==0.3.5
100
  spacy==3.6.1
 
102
  spacy-loggers==1.0.4
103
  srsly==2.4.7
104
  stack-data==0.6.2
 
105
  sympy==1.12
106
  thinc==8.1.11
107
  threadpoolctl==3.2.0
 
108
  torch==2.0.1
109
  torchvision==0.15.2
110
  tornado==6.3.2
111
+ tqdm==4.66.1
112
  traitlets==5.9.0
113
  triton==2.0.0
114
  tsai==0.3.7
115
  typer==0.9.0
116
  typing_extensions==4.7.1
117
  tzdata==2023.3
 
118
  urllib3==2.0.4
 
119
  wasabi==1.1.2
120
  wcwidth==0.2.6
121
+ Werkzeug==2.3.6
122
  wrapt==1.15.0