imperialwool commited on
Commit
ffb7cb9
1 Parent(s): 26f96fe
Files changed (6) hide show
  1. .gitignore +1 -0
  2. app.py +6 -25
  3. requirements.txt +1 -6
  4. routes/config.json +7 -7
  5. routes/helpers.py +1 -1
  6. static/api.yaml +157 -163
.gitignore CHANGED
@@ -2,6 +2,7 @@
2
  __pycache__/
3
  *.py[cod]
4
  *$py.class
 
5
 
6
  # C extensions
7
  *.so
 
2
  __pycache__/
3
  *.py[cod]
4
  *$py.class
5
+ *.pyc
6
 
7
  # C extensions
8
  *.so
app.py CHANGED
@@ -4,12 +4,11 @@ from flask import *
4
  from routes.helpers import configFile
5
  from routes import *
6
 
7
- from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
8
  from random import randint
9
 
10
  #initing
11
  app = Flask(__name__)
12
- VERSION = '1.0 build128'
13
  app.config['JSON_AS_ASCII'] = False
14
 
15
  #error pages
@@ -83,41 +82,23 @@ def getBMPreview(): return osuApi.getPreview(request)
83
  @app.route('/osu/api/v1/get-full', methods=['POST'])
84
  def getBMFull(): return osuApi.getFull(request)
85
 
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
92
- # to understand which text is negative, positive or neutral
93
  @app.route('/analyzeText/api/v1/sentiment', methods=['POST'])
94
  def sentimentAnalys():
95
- try:
96
- text = helpers.getFromRequest(request, "text")
97
- if not text: return {"status": "error", "details": { "error_code": 101, "error_details": "No text provided" }}
98
-
99
- inputs = sa_t(text, return_tensors="pt")
100
 
101
- outputs = sa_m(**inputs)
102
- logits = outputs.logits
103
- predicted_sentiment_index = logits.argmax(dim=1).item()
104
- predicted_sentiment = sa_m.config.id2label[predicted_sentiment_index]
105
-
106
- return {"status": "pass", "predicted_sentiment": predicted_sentiment}
107
- except Exception as e: return {"status": "error", "details": { "error_code": 123, "error_details": str(e).replace("\n", " | ") }}
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
  ##############
115
  # INIT APP
116
  if __name__ == "__main__":
117
  config = configFile()
118
- with open(config['config-path'], "w", encoding="utf-8") as outfile:
119
- config['buildVersion'] = VERSION
120
- json.dump(config, outfile)
121
  with open(config['openapi-yaml-path'], "r+", encoding="utf-8") as outfile:
122
  info = outfile.read()
123
  outfile.seek(0)
 
4
  from routes.helpers import configFile
5
  from routes import *
6
 
 
7
  from random import randint
8
 
9
  #initing
10
  app = Flask(__name__)
11
+ VERSION: str = None
12
  app.config['JSON_AS_ASCII'] = False
13
 
14
  #error pages
 
82
  @app.route('/osu/api/v1/get-full', methods=['POST'])
83
  def getBMFull(): return osuApi.getFull(request)
84
 
 
 
 
 
85
  ##############
86
  # ANALYZE DATA API
87
+ # deprecated
88
  @app.route('/analyzeText/api/v1/sentiment', methods=['POST'])
89
  def sentimentAnalys():
90
+ return {"status": "pass", "predicted_sentiment": "neutral"}
 
 
 
 
91
 
 
 
 
 
 
 
 
92
  @app.route('/analyzeText/api/v1/toxicity', methods=['POST'])
93
  def toxicityAnalys():
94
+ return {"status": "pass", "toxicity": False}
 
 
95
 
96
  ##############
97
  # INIT APP
98
  if __name__ == "__main__":
99
  config = configFile()
100
+ with open(config['config-path'], "r", encoding="utf-8") as outfile:
101
+ VERSION = config['buildVersion']
 
102
  with open(config['openapi-yaml-path'], "r+", encoding="utf-8") as outfile:
103
  info = outfile.read()
104
  outfile.seek(0)
requirements.txt CHANGED
@@ -1,13 +1,8 @@
1
  wget
2
  flask
3
- torch
4
  Pillow
5
  psutil
6
  urllib3
7
  requests
8
  py-cpuinfo
9
- transformers
10
- ffmpeg-python
11
- sentencepiece
12
- tensorflow-cpu
13
- SpeechRecognition
 
1
  wget
2
  flask
 
3
  Pillow
4
  psutil
5
  urllib3
6
  requests
7
  py-cpuinfo
8
+ ffmpeg-python
 
 
 
 
routes/config.json CHANGED
@@ -1,13 +1,13 @@
1
  {
2
  "url": "https://imperialwool-funapi.hf.space",
3
 
4
- "full-path": "/app/static/full",
5
- "temp-path": "/app/static/temp",
6
- "static-path": "/app/static",
7
- "previews-path": "/app/static/previews",
8
 
9
- "config-path": "/app/routes/config.json",
10
- "openapi-yaml-path": "/app/static/api.yaml",
11
 
12
- "buildVersion": "1.0 commit149"
13
  }
 
1
  {
2
  "url": "https://imperialwool-funapi.hf.space",
3
 
4
+ "full-path": "./static/full",
5
+ "temp-path": "./static/temp",
6
+ "static-path": "./static",
7
+ "previews-path": "./static/previews",
8
 
9
+ "config-path": "./routes/config.json",
10
+ "openapi-yaml-path": "./static/api.yaml",
11
 
12
+ "buildVersion": "1.0 commit155"
13
  }
routes/helpers.py CHANGED
@@ -13,7 +13,7 @@ def deleteAudio(path: str, waitInSeconds: int = 0):
13
 
14
  # Config file reading
15
  def configFile():
16
- with open("/app/routes/config.json", "r") as file:
17
  config = json.loads(file.read())
18
  return config
19
 
 
13
 
14
  # Config file reading
15
  def configFile():
16
+ with open("./routes/config.json", "r") as file:
17
  config = json.loads(file.read())
18
  return config
19
 
static/api.yaml CHANGED
@@ -2,125 +2,113 @@
2
  openapi: 3.0.0
3
  info:
4
  title: imperialwool's FunAPI
5
- description: Big API for bots, developers or just fun by @podvaljoey (telegram).
6
  version: $VERSION_VARIABLE$
 
7
  servers:
8
  - url: https://imperialwool-funapi.hf.space/
9
  description: You are here! ^o^
10
  paths:
11
  /analyzeText/api/v1/toxicity:
12
  post:
13
- "200":
14
- description: OK
15
- content: null
16
- application/json:
17
- schema: null
18
- $ref: "#/components/schemas/PredictedToxicityObject"
19
- "400":
20
- description: Bad Request
21
- content: null
22
- application/json:
23
- schema: null
24
- $ref: "#/components/schemas/ErrorObject"
25
- tags:
26
- - Analyze text API
27
  parameters:
28
  - name: text
29
  description: Text to analyze
30
- in: lang
31
  schema:
32
  type: string
33
  example: ru
 
 
34
  summary: Classifying a text as toxic or not toxic
35
- responses: null
 
 
 
 
 
 
 
 
 
 
 
 
36
  /analyzeText/api/v1/sentiment:
37
  post:
38
- "200":
39
- description: OK
40
- content: null
41
- application/json:
42
- schema: null
43
- $ref: "#/components/schemas/PredictedSentimentObject"
44
- "400":
45
- description: Bad Request
46
- content: null
47
- application/json:
48
- schema: null
49
- $ref: "#/components/schemas/ErrorObject"
50
  tags:
51
  - Analyze text API
52
  parameters:
53
  - name: text
54
  description: Text to analyze
55
- in: lang
56
  schema:
57
  type: string
58
  example: ru
59
  summary: Classifying a text as negative, positive or neutral
60
- responses: null
 
 
 
 
 
 
 
 
 
 
 
 
61
  /jokes/api/v1/get:
62
  post:
63
- "200":
64
- description: OK
65
- content: null
66
- application/json:
67
- schema: null
68
- $ref: "#/components/schemas/JokeObject"
69
- "400":
70
- description: Bad Request
71
- content: null
72
- application/json:
73
- schema: null
74
- $ref: "#/components/schemas/ErrorObject"
75
  tags:
76
  - Jokes API
77
  parameters:
78
  - name: lang
79
  description: Language in which to look for a joke. (Now supported only ru, sorry.)
80
- in: lang
81
  schema:
82
  type: string
83
  example: ru
84
  - name: source
85
  description: You can get sources and use one of them, if you like.
86
- in: source
87
  schema:
88
  type: string
89
  example: chucknorris
90
  summary: Finding joke by language
91
- responses: null
 
 
 
 
 
 
 
 
 
 
 
 
92
  /jokes/api/v1/sources:
93
  post:
94
- "200":
95
- description: OK
96
- content: null
97
- application/json:
98
- schema: null
99
- $ref: "#/components/schemas/JokeSourceObject"
100
- "400":
101
- description: Bad Request
102
- content: null
103
- application/json:
104
- schema: null
105
- $ref: "#/components/schemas/ErrorObject"
106
  tags:
107
  - Jokes API
108
  summary: Showing all possible jokes sources
109
- responses: null
 
 
 
 
 
 
 
 
 
 
 
 
110
  /osu/api/v1/find-song:
111
  post:
112
- "200":
113
- description: OK
114
- content: null
115
- application/json:
116
- schema: null
117
- $ref: "#/components/schemas/FindBeatmapsObject"
118
- "400":
119
- description: Bad Request
120
- content: null
121
- application/json:
122
- schema: null
123
- $ref: "#/components/schemas/ErrorObject"
124
  tags:
125
  - osu! API
126
  parameters:
@@ -131,21 +119,21 @@ paths:
131
  type: string
132
  example: rickroll
133
  summary: Finding beatmap by query
134
- responses: null
 
 
 
 
 
 
 
 
 
 
 
 
135
  /osu/api/v1/get-full:
136
  post:
137
- "200":
138
- description: OK
139
- content: null
140
- application/json:
141
- schema: null
142
- $ref: "#/components/schemas/SongFullObject"
143
- "400":
144
- description: Bad Request
145
- content: null
146
- application/json:
147
- schema: null
148
- $ref: "#/components/schemas/ErrorObject"
149
  tags:
150
  - osu! API
151
  parameters:
@@ -162,21 +150,21 @@ paths:
162
  type: integer
163
  example: 1
164
  summary: Get beatmap's full song
165
- responses: null
 
 
 
 
 
 
 
 
 
 
 
 
166
  /osu/api/v1/get-preview:
167
  post:
168
- "200":
169
- description: OK
170
- content: null
171
- application/json:
172
- schema: null
173
- $ref: "#/components/schemas/SongPreviewObject"
174
- "400":
175
- description: Bad Request
176
- content: null
177
- application/json:
178
- schema: null
179
- $ref: "#/components/schemas/ErrorObject"
180
  tags:
181
  - osu! API
182
  parameters:
@@ -193,39 +181,39 @@ paths:
193
  type: integer
194
  example: 1
195
  summary: Get beatmap's song preview
196
- responses: null
 
 
 
 
 
 
 
 
 
 
 
 
197
  /system/api/v1/info:
198
  post:
199
- "200":
200
- description: OK
201
- content: null
202
- application/json:
203
- schema: null
204
- $ref: "#/components/schemas/SysinfoObject"
205
- "400":
206
- description: Bad Request
207
- content: null
208
- application/json:
209
- schema: null
210
- $ref: "#/components/schemas/ErrorObject"
211
  tags:
212
  - System information
213
  summary: Information about server
214
- responses: null
 
 
 
 
 
 
 
 
 
 
 
 
215
  /yt/api/v1/search:
216
  post:
217
- "200":
218
- description: OK
219
- content: null
220
- application/json:
221
- schema: null
222
- $ref: "#/components/schemas/YTSearchObject"
223
- "400":
224
- description: Bad Request
225
- content: null
226
- application/json:
227
- schema: null
228
- $ref: "#/components/schemas/ErrorObject"
229
  tags:
230
  - "Youtube: Becoming Music Platform"
231
  parameters:
@@ -236,21 +224,21 @@ paths:
236
  type: string
237
  example: never gonna give you up
238
  summary: This method can help with searching videos on YouTube
239
- responses: null
 
 
 
 
 
 
 
 
 
 
 
 
240
  /yt/api/v1/get-full:
241
  post:
242
- "200":
243
- description: OK
244
- content: null
245
- application/json:
246
- schema: null
247
- $ref: "#/components/schemas/YTFullObject"
248
- "400":
249
- description: Bad Request
250
- content: null
251
- application/json:
252
- schema: null
253
- $ref: "#/components/schemas/ErrorObject"
254
  tags:
255
  - "Youtube: Becoming Music Platform"
256
  parameters:
@@ -272,21 +260,21 @@ paths:
272
  type: string
273
  example: worst
274
  summary: Download video as audio and providing link for you
275
- responses: null
 
 
 
 
 
 
 
 
 
 
 
 
276
  /yt/api/v1/get-preview:
277
  post:
278
- "200":
279
- description: OK
280
- content: null
281
- application/json:
282
- schema: null
283
- $ref: "#/components/schemas/YTPreviewResult"
284
- "400":
285
- description: Bad Request
286
- content: null
287
- application/json:
288
- schema: null
289
- $ref: "#/components/schemas/ErrorObject"
290
  tags:
291
  - "Youtube: Becoming Music Platform"
292
  parameters:
@@ -314,7 +302,19 @@ paths:
314
  type: integer
315
  example: 45
316
  summary: Download video as cutted audio and providing link for you
317
- responses: null
 
 
 
 
 
 
 
 
 
 
 
 
318
  components:
319
  schemas:
320
  SongFullObject:
@@ -390,7 +390,7 @@ components:
390
  type: string
391
  example: pass
392
  toxicity:
393
- type: bool
394
  example: false
395
  FindBeatmapsObject:
396
  type: object
@@ -434,25 +434,19 @@ components:
434
  lang1:
435
  type: array
436
  items:
437
- - source 1
438
- - source 2
439
- - source 3
440
- - source 4
441
- - source 5
442
  lang2:
443
  type: array
444
  items:
445
- - source 1
446
- - source 2
447
- - source 3
448
- - source 4
449
- - source 5
450
  SysinfoObject:
451
  type: object
452
  properties:
453
  API_VERSION:
454
  type: string
455
- example: $VERSION_VARIABLE$
456
  CPU_INFO:
457
  type: object
458
  properties:
@@ -507,7 +501,7 @@ components:
507
  properties:
508
  error_code:
509
  type: integer
510
- example: 1337
511
  error_details:
512
  type: string
513
  example: Some error
 
2
  openapi: 3.0.0
3
  info:
4
  title: imperialwool's FunAPI
 
5
  version: $VERSION_VARIABLE$
6
+ description: Big API for bots, developers or just fun by @podvaljoey (telegram).
7
  servers:
8
  - url: https://imperialwool-funapi.hf.space/
9
  description: You are here! ^o^
10
  paths:
11
  /analyzeText/api/v1/toxicity:
12
  post:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  parameters:
14
  - name: text
15
  description: Text to analyze
16
+ in: query
17
  schema:
18
  type: string
19
  example: ru
20
+ tags:
21
+ - Analyze text API
22
  summary: Classifying a text as toxic or not toxic
23
+ responses:
24
+ "200":
25
+ description: OK
26
+ content:
27
+ application/json:
28
+ schema:
29
+ $ref: "#/components/schemas/PredictedToxicityObject"
30
+ "400":
31
+ description: Bad Request
32
+ content:
33
+ application/json:
34
+ schema:
35
+ $ref: "#/components/schemas/ErrorObject"
36
  /analyzeText/api/v1/sentiment:
37
  post:
 
 
 
 
 
 
 
 
 
 
 
 
38
  tags:
39
  - Analyze text API
40
  parameters:
41
  - name: text
42
  description: Text to analyze
43
+ in: query
44
  schema:
45
  type: string
46
  example: ru
47
  summary: Classifying a text as negative, positive or neutral
48
+ responses:
49
+ "200":
50
+ description: OK
51
+ content:
52
+ application/json:
53
+ schema:
54
+ $ref: "#/components/schemas/PredictedSentimentObject"
55
+ "400":
56
+ description: Bad Request
57
+ content:
58
+ application/json:
59
+ schema:
60
+ $ref: "#/components/schemas/ErrorObject"
61
  /jokes/api/v1/get:
62
  post:
 
 
 
 
 
 
 
 
 
 
 
 
63
  tags:
64
  - Jokes API
65
  parameters:
66
  - name: lang
67
  description: Language in which to look for a joke. (Now supported only ru, sorry.)
68
+ in: query
69
  schema:
70
  type: string
71
  example: ru
72
  - name: source
73
  description: You can get sources and use one of them, if you like.
74
+ in: query
75
  schema:
76
  type: string
77
  example: chucknorris
78
  summary: Finding joke by language
79
+ responses:
80
+ "200":
81
+ description: OK
82
+ content:
83
+ application/json:
84
+ schema:
85
+ $ref: "#/components/schemas/JokeObject"
86
+ "400":
87
+ description: Bad Request
88
+ content:
89
+ application/json:
90
+ schema:
91
+ $ref: "#/components/schemas/ErrorObject"
92
  /jokes/api/v1/sources:
93
  post:
 
 
 
 
 
 
 
 
 
 
 
 
94
  tags:
95
  - Jokes API
96
  summary: Showing all possible jokes sources
97
+ responses:
98
+ "200":
99
+ description: OK
100
+ content:
101
+ application/json:
102
+ schema:
103
+ $ref: "#/components/schemas/JokeSourceObject"
104
+ "400":
105
+ description: Bad Request
106
+ content:
107
+ application/json:
108
+ schema:
109
+ $ref: "#/components/schemas/ErrorObject"
110
  /osu/api/v1/find-song:
111
  post:
 
 
 
 
 
 
 
 
 
 
 
 
112
  tags:
113
  - osu! API
114
  parameters:
 
119
  type: string
120
  example: rickroll
121
  summary: Finding beatmap by query
122
+ responses:
123
+ "200":
124
+ description: OK
125
+ content:
126
+ application/json:
127
+ schema:
128
+ $ref: "#/components/schemas/FindBeatmapsObject"
129
+ "400":
130
+ description: Bad Request
131
+ content:
132
+ application/json:
133
+ schema:
134
+ $ref: "#/components/schemas/ErrorObject"
135
  /osu/api/v1/get-full:
136
  post:
 
 
 
 
 
 
 
 
 
 
 
 
137
  tags:
138
  - osu! API
139
  parameters:
 
150
  type: integer
151
  example: 1
152
  summary: Get beatmap's full song
153
+ responses:
154
+ "200":
155
+ description: OK
156
+ content:
157
+ application/json:
158
+ schema:
159
+ $ref: "#/components/schemas/SongFullObject"
160
+ "400":
161
+ description: Bad Request
162
+ content:
163
+ application/json:
164
+ schema:
165
+ $ref: "#/components/schemas/ErrorObject"
166
  /osu/api/v1/get-preview:
167
  post:
 
 
 
 
 
 
 
 
 
 
 
 
168
  tags:
169
  - osu! API
170
  parameters:
 
181
  type: integer
182
  example: 1
183
  summary: Get beatmap's song preview
184
+ responses:
185
+ "200":
186
+ description: OK
187
+ content:
188
+ application/json:
189
+ schema:
190
+ $ref: "#/components/schemas/SongPreviewObject"
191
+ "400":
192
+ description: Bad Request
193
+ content:
194
+ application/json:
195
+ schema:
196
+ $ref: "#/components/schemas/ErrorObject"
197
  /system/api/v1/info:
198
  post:
 
 
 
 
 
 
 
 
 
 
 
 
199
  tags:
200
  - System information
201
  summary: Information about server
202
+ responses:
203
+ "200":
204
+ description: OK
205
+ content:
206
+ application/json:
207
+ schema:
208
+ $ref: "#/components/schemas/SysinfoObject"
209
+ "400":
210
+ description: Bad Request
211
+ content:
212
+ application/json:
213
+ schema:
214
+ $ref: "#/components/schemas/ErrorObject"
215
  /yt/api/v1/search:
216
  post:
 
 
 
 
 
 
 
 
 
 
 
 
217
  tags:
218
  - "Youtube: Becoming Music Platform"
219
  parameters:
 
224
  type: string
225
  example: never gonna give you up
226
  summary: This method can help with searching videos on YouTube
227
+ responses:
228
+ "200":
229
+ description: OK
230
+ content:
231
+ application/json:
232
+ schema:
233
+ $ref: "#/components/schemas/YTSearchObject"
234
+ "400":
235
+ description: Bad Request
236
+ content:
237
+ application/json:
238
+ schema:
239
+ $ref: "#/components/schemas/ErrorObject"
240
  /yt/api/v1/get-full:
241
  post:
 
 
 
 
 
 
 
 
 
 
 
 
242
  tags:
243
  - "Youtube: Becoming Music Platform"
244
  parameters:
 
260
  type: string
261
  example: worst
262
  summary: Download video as audio and providing link for you
263
+ responses:
264
+ "200":
265
+ description: OK
266
+ content:
267
+ application/json:
268
+ schema:
269
+ $ref: "#/components/schemas/YTFullObject"
270
+ "400":
271
+ description: Bad Request
272
+ content:
273
+ application/json:
274
+ schema:
275
+ $ref: "#/components/schemas/ErrorObject"
276
  /yt/api/v1/get-preview:
277
  post:
 
 
 
 
 
 
 
 
 
 
 
 
278
  tags:
279
  - "Youtube: Becoming Music Platform"
280
  parameters:
 
302
  type: integer
303
  example: 45
304
  summary: Download video as cutted audio and providing link for you
305
+ responses:
306
+ "200":
307
+ description: OK
308
+ content:
309
+ application/json:
310
+ schema:
311
+ $ref: "#/components/schemas/YTPreviewResult"
312
+ "400":
313
+ description: Bad Request
314
+ content:
315
+ application/json:
316
+ schema:
317
+ $ref: "#/components/schemas/ErrorObject"
318
  components:
319
  schemas:
320
  SongFullObject:
 
390
  type: string
391
  example: pass
392
  toxicity:
393
+ type: boolean
394
  example: false
395
  FindBeatmapsObject:
396
  type: object
 
434
  lang1:
435
  type: array
436
  items:
437
+ type: string
438
+ example: source
 
 
 
439
  lang2:
440
  type: array
441
  items:
442
+ type: string
443
+ example: source
 
 
 
444
  SysinfoObject:
445
  type: object
446
  properties:
447
  API_VERSION:
448
  type: string
449
+ example: 1.0 build128
450
  CPU_INFO:
451
  type: object
452
  properties:
 
501
  properties:
502
  error_code:
503
  type: integer
504
+ example: 1111
505
  error_details:
506
  type: string
507
  example: Some error