File size: 1,396 Bytes
9d3162f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from flask import Flask,request
from flask_cors import cross_origin
from flask_socketio import SocketIO,send,emit
from CaesarYolo import CaesarYolo
import numpy as np
import base64
caesaryolo = CaesarYolo()
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app)


@app.route("/",methods=["GET"])
@cross_origin()
def caesaraihome():
    return "Welcome to CaesarAI's API's and CaesarAINL."
@app.route("/caesarobjectdetect",methods=["POST"])
def caesarobjectdetect():
    frames = request.get_json()
    #print(frames)
    
    image = caesaryolo.caesar_object_detect(np.frombuffer(base64.b64decode(frames["frame"]),dtype="uint8").reshape(480,640,3))#base64.b64decode(frames["frame"]))
    return {'frame': base64.b64encode(image).decode()}

@socketio.on('message')
def message(data):
    print(data)  # {'from': 'client'}
    emit('response', {'from': 'server'})

@socketio.on('man')
def message(data):
    print(data)  # {'from': 'client'}
    emit('response', {'from': 'server man'})
@socketio.on('caesarobjectdetect')
def caesarobjectdetect(image):
    image = caesaryolo.caesar_object_detect(np.array(image["frame"]))
    emit('caesarobjectresponse',  {'frame': str(image)})

if __name__ == "__main__":
    #port = int(os.environ.get('PORT', 5000)) # 80
    app.run(debug=True,host="0.0.0.0",port=5000) 
    #socketio.run(app,debug=True,host="0.0.0.0",port=5000)