-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
42 lines (29 loc) · 1.01 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import os
from flask import Flask, request
from flask_cors import cross_origin
from helpers import download_file
from nlp import get_ner_and_verbs
from transform import get_video_labels
app = Flask(__name__)
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg'}
def allowed_file(filename):
# xxx.png
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@app.route('/api/files/<cid>/context', methods=['POST'])
@cross_origin()
def annotate_video(cid):
content = request.json
ipfs_url = 'https://ipfs.io' + content['ipfsPath']
temporary_path = os.path.join('temporary')
local_filename = download_file(ipfs_url, temporary_path)
local_path = os.path.join('temporary', local_filename)
# Extract video labels via Pytorch video
labels = get_video_labels(local_path)
return {
"labels": labels
}
@app.route('/api/annotate', methods=['POST'])
@cross_origin()
def annotate_text():
content = request.json
return get_ner_and_verbs(content['description'])