-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.py
46 lines (32 loc) · 935 Bytes
/
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
42
43
44
45
46
import os
from threading import Thread
from flask import Flask, render_template, request
from flask_cors import CORS
from werkzeug.utils import secure_filename
from finetune import train_custom
UPLOAD_FOLDER = './mydata'
ALLOWED_EXTENSIONS = set(['.tsv'])
app = Flask(__name__)
CORS(app)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
@app.route('/')
def index():
return render_template('index.html')
@app.route('/createWebApp', methods=['POST'])
def webapp():
title = request.args.get('text')
if not os.path.exists('./my-app-'+title):
os.makedirs('./my-app-'+title)
@app.route('/trainAndstream', methods=['POST'])
def trainAndstream():
file = request.files['filename']
filename = file.filename
filepath = os.path.join(app.config['UPLOAD_FOLDER'], filename)
file.save(filepath)
def do_work():
train_custom(filepath)
thread = Thread(target=do_work)
thread.start()
thread.join()
return '1'
app.run(debug=True)