Spaces:
Runtime error
Runtime error
imperialwool
commited on
Commit
•
a39dd78
1
Parent(s):
0b5904d
upd: rewrite audio downloading
Browse files- .gitignore +160 -0
- .vscode/settings.json +0 -3
- app.py +1 -12
- routes/config.json +1 -1
- routes/helpers.py +3 -0
- routes/ytApi/get.py +0 -37
- routes/ytApi/getFull.py +48 -23
- routes/ytApi/getPreview.py +51 -27
.gitignore
ADDED
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Byte-compiled / optimized / DLL files
|
2 |
+
__pycache__/
|
3 |
+
*.py[cod]
|
4 |
+
*$py.class
|
5 |
+
|
6 |
+
# C extensions
|
7 |
+
*.so
|
8 |
+
|
9 |
+
# Distribution / packaging
|
10 |
+
.Python
|
11 |
+
build/
|
12 |
+
develop-eggs/
|
13 |
+
dist/
|
14 |
+
downloads/
|
15 |
+
eggs/
|
16 |
+
.eggs/
|
17 |
+
lib/
|
18 |
+
lib64/
|
19 |
+
parts/
|
20 |
+
sdist/
|
21 |
+
var/
|
22 |
+
wheels/
|
23 |
+
share/python-wheels/
|
24 |
+
*.egg-info/
|
25 |
+
.installed.cfg
|
26 |
+
*.egg
|
27 |
+
MANIFEST
|
28 |
+
|
29 |
+
# PyInstaller
|
30 |
+
# Usually these files are written by a python script from a template
|
31 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
32 |
+
*.manifest
|
33 |
+
*.spec
|
34 |
+
|
35 |
+
# Installer logs
|
36 |
+
pip-log.txt
|
37 |
+
pip-delete-this-directory.txt
|
38 |
+
|
39 |
+
# Unit test / coverage reports
|
40 |
+
htmlcov/
|
41 |
+
.tox/
|
42 |
+
.nox/
|
43 |
+
.coverage
|
44 |
+
.coverage.*
|
45 |
+
.cache
|
46 |
+
nosetests.xml
|
47 |
+
coverage.xml
|
48 |
+
*.cover
|
49 |
+
*.py,cover
|
50 |
+
.hypothesis/
|
51 |
+
.pytest_cache/
|
52 |
+
cover/
|
53 |
+
|
54 |
+
# Translations
|
55 |
+
*.mo
|
56 |
+
*.pot
|
57 |
+
|
58 |
+
# Django stuff:
|
59 |
+
*.log
|
60 |
+
local_settings.py
|
61 |
+
db.sqlite3
|
62 |
+
db.sqlite3-journal
|
63 |
+
|
64 |
+
# Flask stuff:
|
65 |
+
instance/
|
66 |
+
.webassets-cache
|
67 |
+
|
68 |
+
# Scrapy stuff:
|
69 |
+
.scrapy
|
70 |
+
|
71 |
+
# Sphinx documentation
|
72 |
+
docs/_build/
|
73 |
+
|
74 |
+
# PyBuilder
|
75 |
+
.pybuilder/
|
76 |
+
target/
|
77 |
+
|
78 |
+
# Jupyter Notebook
|
79 |
+
.ipynb_checkpoints
|
80 |
+
|
81 |
+
# IPython
|
82 |
+
profile_default/
|
83 |
+
ipython_config.py
|
84 |
+
|
85 |
+
# pyenv
|
86 |
+
# For a library or package, you might want to ignore these files since the code is
|
87 |
+
# intended to run in multiple environments; otherwise, check them in:
|
88 |
+
# .python-version
|
89 |
+
|
90 |
+
# pipenv
|
91 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
92 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
93 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
94 |
+
# install all needed dependencies.
|
95 |
+
#Pipfile.lock
|
96 |
+
|
97 |
+
# poetry
|
98 |
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
99 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
100 |
+
# commonly ignored for libraries.
|
101 |
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
102 |
+
#poetry.lock
|
103 |
+
|
104 |
+
# pdm
|
105 |
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
106 |
+
#pdm.lock
|
107 |
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
108 |
+
# in version control.
|
109 |
+
# https://pdm.fming.dev/#use-with-ide
|
110 |
+
.pdm.toml
|
111 |
+
|
112 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
113 |
+
__pypackages__/
|
114 |
+
|
115 |
+
# Celery stuff
|
116 |
+
celerybeat-schedule
|
117 |
+
celerybeat.pid
|
118 |
+
|
119 |
+
# SageMath parsed files
|
120 |
+
*.sage.py
|
121 |
+
|
122 |
+
# Environments
|
123 |
+
.env
|
124 |
+
.venv
|
125 |
+
env/
|
126 |
+
venv/
|
127 |
+
ENV/
|
128 |
+
env.bak/
|
129 |
+
venv.bak/
|
130 |
+
|
131 |
+
# Spyder project settings
|
132 |
+
.spyderproject
|
133 |
+
.spyproject
|
134 |
+
|
135 |
+
# Rope project settings
|
136 |
+
.ropeproject
|
137 |
+
|
138 |
+
# mkdocs documentation
|
139 |
+
/site
|
140 |
+
|
141 |
+
# mypy
|
142 |
+
.mypy_cache/
|
143 |
+
.dmypy.json
|
144 |
+
dmypy.json
|
145 |
+
|
146 |
+
# Pyre type checker
|
147 |
+
.pyre/
|
148 |
+
|
149 |
+
# pytype static type analyzer
|
150 |
+
.pytype/
|
151 |
+
|
152 |
+
# Cython debug symbols
|
153 |
+
cython_debug/
|
154 |
+
|
155 |
+
# PyCharm
|
156 |
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
157 |
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
158 |
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
159 |
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
160 |
+
#.idea/
|
.vscode/settings.json
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"python.analysis.typeCheckingMode": "off"
|
3 |
-
}
|
|
|
|
|
|
|
|
app.py
CHANGED
@@ -86,7 +86,6 @@ def getBMFull(): return osuApi.getFull(request)
|
|
86 |
###############
|
87 |
# LOAD MODELS
|
88 |
sa_t, sa_m = AutoTokenizer.from_pretrained("cardiffnlp/twitter-xlm-roberta-base-sentiment"), AutoModelForSequenceClassification.from_pretrained("cardiffnlp/twitter-xlm-roberta-base-sentiment")
|
89 |
-
tc_t, tc_m = AutoTokenizer.from_pretrained("EIStakovskii/xlm_roberta_base_multilingual_toxicity_classifier_plus"), AutoModelForSequenceClassification.from_pretrained("EIStakovskii/xlm_roberta_base_multilingual_toxicity_classifier_plus")
|
90 |
|
91 |
##############
|
92 |
# ANALYZE DATA API
|
@@ -109,17 +108,7 @@ def sentimentAnalys():
|
|
109 |
@app.route('/analyzeText/api/v1/toxicity', methods=['POST'])
|
110 |
def toxicityAnalys():
|
111 |
try:
|
112 |
-
|
113 |
-
if not text: return {"status": "error", "details": { "error_code": 101, "error_details": "No text provided" }} , 400
|
114 |
-
|
115 |
-
inputs = tc_t(text, return_tensors="pt")
|
116 |
-
|
117 |
-
outputs = tc_m(**inputs)
|
118 |
-
logits = outputs.logits
|
119 |
-
predicted_class = logits.argmax(dim=1).item()
|
120 |
-
predicted_sentiment = True if str(tc_m.config.id2label[predicted_class]) == "LABEL_1" else False
|
121 |
-
|
122 |
-
return {"status": "pass", "toxicity": predicted_sentiment}
|
123 |
except Exception as e: return {"status": "error", "details": { "error_code": 123, "error_details": str(e).replace("\n", " | ") }} , 400
|
124 |
|
125 |
##############
|
|
|
86 |
###############
|
87 |
# LOAD MODELS
|
88 |
sa_t, sa_m = AutoTokenizer.from_pretrained("cardiffnlp/twitter-xlm-roberta-base-sentiment"), AutoModelForSequenceClassification.from_pretrained("cardiffnlp/twitter-xlm-roberta-base-sentiment")
|
|
|
89 |
|
90 |
##############
|
91 |
# ANALYZE DATA API
|
|
|
108 |
@app.route('/analyzeText/api/v1/toxicity', methods=['POST'])
|
109 |
def toxicityAnalys():
|
110 |
try:
|
111 |
+
return {"status": "pass", "toxicity": False}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
except Exception as e: return {"status": "error", "details": { "error_code": 123, "error_details": str(e).replace("\n", " | ") }} , 400
|
113 |
|
114 |
##############
|
routes/config.json
CHANGED
@@ -9,5 +9,5 @@
|
|
9 |
"config-path": "/app/routes/config.json",
|
10 |
"openapi-yaml-path": "/app/static/api.yaml",
|
11 |
|
12 |
-
"buildVersion": "1.0
|
13 |
}
|
|
|
9 |
"config-path": "/app/routes/config.json",
|
10 |
"openapi-yaml-path": "/app/static/api.yaml",
|
11 |
|
12 |
+
"buildVersion": "1.0 commit149"
|
13 |
}
|
routes/helpers.py
CHANGED
@@ -2,9 +2,12 @@ import os
|
|
2 |
import json
|
3 |
import random
|
4 |
import string
|
|
|
5 |
|
6 |
# Deleting audio
|
7 |
def deleteAudio(path: str, waitInSeconds: int = 0):
|
|
|
|
|
8 |
config = configFile()
|
9 |
os.system("rm {}/{}".format(config['static-path'], path))
|
10 |
|
|
|
2 |
import json
|
3 |
import random
|
4 |
import string
|
5 |
+
from time import sleep
|
6 |
|
7 |
# Deleting audio
|
8 |
def deleteAudio(path: str, waitInSeconds: int = 0):
|
9 |
+
if waitInSeconds:
|
10 |
+
sleep(waitInSeconds)
|
11 |
config = configFile()
|
12 |
os.system("rm {}/{}".format(config['static-path'], path))
|
13 |
|
routes/ytApi/get.py
DELETED
@@ -1,37 +0,0 @@
|
|
1 |
-
import os
|
2 |
-
import yt_dlp
|
3 |
-
from .. import helpers
|
4 |
-
|
5 |
-
def get(request, check = "huh"):
|
6 |
-
url = helpers.getFromRequest(request, "url")
|
7 |
-
if not url: return {"status": "error", "details": { "error_code": 101, "error_details": "No link provided" }}, 400
|
8 |
-
|
9 |
-
bitrate = helpers.getFromRequest(request, "bitrate")
|
10 |
-
if not bitrate: bitrate = "64k"
|
11 |
-
|
12 |
-
quality = helpers.getFromRequest(request, "quality")
|
13 |
-
if not quality or quality.lower() not in ['best', 'worst']: quality = 'worst'
|
14 |
-
else: quality = quality.lower()
|
15 |
-
|
16 |
-
urlcode = url.partition('?v=')[2]
|
17 |
-
if not urlcode: urlcode = "NPRNRQh2fAo"
|
18 |
-
|
19 |
-
config = helpers.configFile()
|
20 |
-
|
21 |
-
if os.path.exists(f"{config['static-path']}/{check}/{urlcode}.ogg"):
|
22 |
-
return {"status": "pass", 'done-or-not': True, 'ytdlp-code': 0, 'urlcode': urlcode, "path": f"{config['static-path']}/{check}/{urlcode}.ogg", "quality": quality, "bitrate": bitrate}
|
23 |
-
|
24 |
-
if os.path.exists(f"{config['temp-path']}/{urlcode}.ogg"):
|
25 |
-
return {"status": "pass", 'done-or-not': False, 'ytdlp-code': 0, 'urlcode': urlcode, "path": f"{config['temp-path']}/{urlcode}.ogg", "quality": quality, "bitrate": bitrate}
|
26 |
-
|
27 |
-
ydl_opts = {
|
28 |
-
'format': f'ogg/{quality}audio/{quality}',
|
29 |
-
'outtmpl': f"{config['temp-path']}/{urlcode}.ogg",
|
30 |
-
'progress_hooks': [helpers.thisIsHook],
|
31 |
-
}
|
32 |
-
|
33 |
-
try:
|
34 |
-
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
35 |
-
error_code = ydl.download(url)
|
36 |
-
except Exception as e: return {"status": "error", "details": {"error_code": 102, "error_details": str(e)}}, 400
|
37 |
-
return {"status": "pass", 'done-or-not': False, 'ytdlp-code': error_code, 'urlcode': urlcode, "path": f"{config['temp-path']}/{urlcode}.ogg", "quality": quality, "bitrate": bitrate}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
routes/ytApi/getFull.py
CHANGED
@@ -1,31 +1,56 @@
|
|
1 |
-
import
|
2 |
-
|
3 |
from .. import helpers
|
4 |
|
5 |
def getFull(request):
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
quality =
|
15 |
-
|
|
|
|
|
16 |
|
17 |
-
|
18 |
-
if not
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
config = helpers.configFile()
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
try:
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import yt_dlp
|
3 |
from .. import helpers
|
4 |
|
5 |
def getFull(request):
|
6 |
+
error_code = None
|
7 |
+
|
8 |
+
url = helpers.getFromRequest(request, "url")
|
9 |
+
if not url: return {"status": "error", "details": { "error_code": 101, "error_details": "No link provided" }}, 400
|
10 |
+
|
11 |
+
bitrate = helpers.getFromRequest(request, "bitrate")
|
12 |
+
if not bitrate: bitrate = "64k"
|
13 |
+
|
14 |
+
quality = helpers.getFromRequest(request, "quality")
|
15 |
+
if not quality or quality.lower() not in ['best', 'worst']:
|
16 |
+
quality = 'worst'
|
17 |
+
else: quality = quality.lower()
|
18 |
|
19 |
+
audioformat = helpers.getFromRequest(request, "audioformat")
|
20 |
+
if not audioformat or audioformat.lower() not in ['m4a', 'aac', 'mp3', 'ogg', 'opus', 'webm']:
|
21 |
+
audioformat = 'ogg'
|
22 |
+
else: audioformat = audioformat.lower()
|
23 |
+
|
24 |
+
urlcode = url.partition('?v=')[2]
|
25 |
+
if not urlcode: urlcode = "NPRNRQh2fAo"
|
26 |
|
27 |
config = helpers.configFile()
|
28 |
+
|
29 |
+
if os.path.exists(f"{config['full-path']}/{urlcode}.{audioformat}"):
|
30 |
+
return {
|
31 |
+
"status": "pass",
|
32 |
+
"details": {
|
33 |
+
"code": error_code,
|
34 |
+
"name":f"{urlcode}.{audioformat}",
|
35 |
+
"result": f"{config['url']}/static/full/{urlcode}.{audioformat}"
|
36 |
+
}
|
37 |
+
}
|
38 |
|
39 |
+
ydl_opts = {
|
40 |
+
'format': f'{audioformat}/{quality}audio/{quality}',
|
41 |
+
'outtmpl': f"{config['full-path']}/{urlcode}.{audioformat}",
|
42 |
+
'progress_hooks': [helpers.thisIsHook],
|
43 |
+
}
|
44 |
+
|
45 |
try:
|
46 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
47 |
+
error_code = ydl.download(url)
|
48 |
+
except Exception as e: return {"status": "error", "details": {"error_code": 102, "error_details": str(e)}}, 400
|
49 |
+
return {
|
50 |
+
"status": "pass",
|
51 |
+
"details": {
|
52 |
+
"code": error_code,
|
53 |
+
"name":f"{urlcode}.{audioformat}",
|
54 |
+
"result": f"{config['url']}/static/full/{urlcode}.{audioformat}"
|
55 |
+
}
|
56 |
+
}
|
routes/ytApi/getPreview.py
CHANGED
@@ -1,41 +1,65 @@
|
|
1 |
import os
|
2 |
-
import
|
3 |
-
from .get import *
|
4 |
from .. import helpers
|
|
|
5 |
|
6 |
def getPreview(request):
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
|
|
|
|
|
|
17 |
duration = helpers.getFromRequest(request, "duration")
|
18 |
try: duration = int(duration)
|
19 |
except Exception as e:
|
20 |
print(e)
|
21 |
duration = 45
|
22 |
|
23 |
-
extension = helpers.getFromRequest(request, "extension")
|
24 |
-
if not extension: extension = "ogg"
|
25 |
-
|
26 |
config = helpers.configFile()
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
try:
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
+
import yt_dlp
|
|
|
3 |
from .. import helpers
|
4 |
+
from yt_dlp.utils import download_range_func
|
5 |
|
6 |
def getPreview(request):
|
7 |
+
error_code = None
|
8 |
+
|
9 |
+
url = helpers.getFromRequest(request, "url")
|
10 |
+
if not url: return {"status": "error", "details": { "error_code": 101, "error_details": "No link provided" }}, 400
|
11 |
+
|
12 |
+
bitrate = helpers.getFromRequest(request, "bitrate")
|
13 |
+
if not bitrate: bitrate = "64k"
|
14 |
+
|
15 |
+
quality = helpers.getFromRequest(request, "quality")
|
16 |
+
if not quality or quality.lower() not in ['best', 'worst']:
|
17 |
+
quality = 'worst'
|
18 |
+
else: quality = quality.lower()
|
19 |
+
|
20 |
+
audioformat = helpers.getFromRequest(request, "audioformat")
|
21 |
+
if not audioformat or audioformat.lower() not in ['m4a', 'aac', 'mp3', 'ogg', 'opus', 'webm']:
|
22 |
+
audioformat = 'ogg'
|
23 |
+
else: audioformat = audioformat.lower()
|
24 |
|
25 |
+
urlcode = url.partition('?v=')[2]
|
26 |
+
if not urlcode: urlcode = "NPRNRQh2fAo"
|
27 |
+
|
28 |
duration = helpers.getFromRequest(request, "duration")
|
29 |
try: duration = int(duration)
|
30 |
except Exception as e:
|
31 |
print(e)
|
32 |
duration = 45
|
33 |
|
|
|
|
|
|
|
34 |
config = helpers.configFile()
|
35 |
+
|
36 |
+
if os.path.exists(f"{config['previews-path']}/{urlcode}.{audioformat}"):
|
37 |
+
return {
|
38 |
+
"status": "pass",
|
39 |
+
"details": {
|
40 |
+
"code": error_code,
|
41 |
+
"name":f"{urlcode}.{audioformat}",
|
42 |
+
"result": f"{config['url']}/static/previews/{urlcode}.{audioformat}"
|
43 |
+
}
|
44 |
+
}
|
45 |
|
46 |
+
ydl_opts = {
|
47 |
+
'format': f'{audioformat}/{quality}audio/{quality}',
|
48 |
+
'outtmpl': f"{config['previews-path']}/{urlcode}.{audioformat}",
|
49 |
+
'progress_hooks': [helpers.thisIsHook],
|
50 |
+
'download_ranges': download_range_func(None, [(0, duration)]),
|
51 |
+
'force_keyframes_at_cuts': True,
|
52 |
+
}
|
53 |
+
|
54 |
try:
|
55 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
56 |
+
error_code = ydl.download(url)
|
57 |
+
except Exception as e: return {"status": "error", "details": {"error_code": 102, "error_details": str(e)}}, 400
|
58 |
+
return {
|
59 |
+
"status": "pass",
|
60 |
+
"details": {
|
61 |
+
"code": error_code,
|
62 |
+
"name":f"{urlcode}.{audioformat}",
|
63 |
+
"result": f"{config['url']}/static/previews/{urlcode}.{audioformat}"
|
64 |
+
}
|
65 |
+
}
|