-
Notifications
You must be signed in to change notification settings - Fork 0
/
testbe.py
66 lines (48 loc) · 1.96 KB
/
testbe.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import random
import string
from flask import Flask, request, jsonify
from flask_cors import CORS
import os
app = Flask(__name__)
CORS(app)
# A list of words
words = ["apple", "banana", "cherry", "date", "elderberry", "fig", "grape", "honeydew", "ice", "jackfruit", "kiwi", "lemon", "mango", "nectarine", "orange", "pineapple", "quince", "raspberry", "strawberry", "tangerine", "ugli", "victoria", "watermelon", "xigua", "yellow", "zucchini"]
@app.route("/api/hello", methods=["GET"])
def say_hello():
return jsonify({"msg": "Hello from Flask"})
@app.route('/api/data', methods=['POST'])
def upload_file():
if 'file' not in request.files:
return jsonify({'error': 'No file part in the request'}), 400
file = request.files['file']
if file.filename == '':
return jsonify({'error': 'No selected file'}), 400
if file and file.filename.endswith('.zip'):
file.save(file.filename)
print('File saved successfully!')
return jsonify({'message': 'File successfully uploaded'}), 200
else:
return jsonify({'error': 'Unsupported file type'}), 400
@app.route('/api/infer', methods=['POST'])
def classify():
if 'file' not in request.files:
return jsonify({'error': 'No file part in the request'}), 400
file = request.files['file']
if file.filename == '':
return jsonify({'error': 'No selected file'}), 400
file.save(file.filename)
# Generate a random string of length 10
random_string = random.choice(words)
return random_string, 200
@app.route('/api/training', methods=['POST'])
def starttraining():
return jsonify({'message': 'OK'}), 200
@app.route('/api/serving', methods=['POST'])
def startserving():
return jsonify({'message': 'OK'}), 200
@app.route('/api/serving', methods=['DELETE'])
def stopserving():
return jsonify({'message': 'OK'}), 200
if __name__ == '__main__':
# Please do not set debug=True in production
app.run(host="0.0.0.0", port=5000, debug=True)