-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
131 lines (85 loc) · 2.56 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
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
from flask import Flask, request, jsonify
from flask_sock import Sock
import pyaudio
app = Flask(__name__)
sock = Sock(app)
# test websocket endpoint
@sock.route('/api/test', methods=['GET'])
def test(ws):
while True:
ws.send("hello world")
####################################################################
# detection endpoints
@app.route('/api/detection', methods=['GET'])
def detactions_options():
return '***'
@sock.route('/api/detection/audio', methods=['GET'])
def get_audio(ws):
audio_format = pyaudio.paInt16
channels = 1
sample_rate = 44100
chunk_size = 512
audio = pyaudio.PyAudio()
stream = audio.open(format=audio_format, channels=channels, rate=sample_rate, input=True, frames_per_buffer=chunk_size, input_device_index=0)
try:
while True:
data = stream.read(1024)
print(data)
print('_________________________________________')
ws.send(data)
except KeyboardInterrupt:
pass
stream.stop_stream()
stream.close()
audio.terminate()
@app.route('/api/detection/detectShot', methods=['POST'])
def detect_shot():
if 'file' not in request.files:
return 'No file part in the request'
file = request.files['file']
if file.filename == '':
return 'No selected file'
# send file to shot detector
# get return and return
resp = {
'shot':True
}
return jsonify(resp)
@app.route('/api/detection/getLocation', methods=['POST'])
def get_location():
if 'file' not in request.files:
return 'No file part in the request'
file = request.files['file']
if file.filename == '':
return 'No selected file'
# noice redection
# send file to audio madel
# return value
return 'File uploaded successfully'
# drone endpoints
@app.route('/api/drone', methods=['GET'])
def drone_options():
return 'drone_options'
@app.route('/api/drone/chooseDrone', methods=['POST'])
def choose_drone():
return 'choose_drone'
@app.route('/api/drone/sendDrone', methods=['POST'])
def send_drone():
return 'send_drone'
# TOTO CV endpoints
@sock.route('/api/toto', methods=['GET'])
def toto_options(ws):
while True:
data = ws.receive()
ws.send(data[::-1])
return 'drone_options'
@app.route('/api/toto/getObjects', methods=['POST'])
def get_objects():
return 'get_objects'
# surge endpoints
@app.route('/api/surge', methods=['GET'])
def surge_options():
return 'surge_options'
# cloud endpoints
if __name__ == '__main__':
app.run()