-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinference.py
More file actions
36 lines (24 loc) · 771 Bytes
/
inference.py
File metadata and controls
36 lines (24 loc) · 771 Bytes
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
import io
import utils
import config
from models import CACNet
from flask_ngrok import run_with_ngrok
from flask import Flask, jsonify, request
app = Flask(__name__, static_folder='./static')
run_with_ngrok(app)
@app.route('/crop/image', methods=['POST'])
def predict():
global model
if request.method == 'POST':
file = request.files['file']
img_bytes = file.read()
input_image = io.BytesIO(img_bytes)
best_crop = utils.apply_cacnet(input_image)
best_crop.save('./static/output.png')
return jsonify({'result': 'static/output.png'})
if __name__ == '__main__':
model = CACNet()
model = model.to(config.DEVICE)
if utils.can_load_checkpoint():
utils.load_checkpoint(model)
app.run()