-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathserver.py
More file actions
54 lines (47 loc) · 1.69 KB
/
server.py
File metadata and controls
54 lines (47 loc) · 1.69 KB
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
#!/usr/bin/env python3
"""
CORS-enabled development server for Visual Reasoning Playground.
Allows sample videos to work with AI detection locally.
Usage:
python server.py
Then open http://localhost:8000 in your browser.
"""
from http.server import HTTPServer, SimpleHTTPRequestHandler
import sys
class CORSRequestHandler(SimpleHTTPRequestHandler):
def end_headers(self):
self.send_header('Access-Control-Allow-Origin', '*')
self.send_header('Access-Control-Allow-Methods', 'GET, OPTIONS')
self.send_header('Access-Control-Allow-Headers', '*')
self.send_header('Cache-Control', 'no-store, no-cache, must-revalidate')
super().end_headers()
def do_OPTIONS(self):
self.send_response(200)
self.end_headers()
extensions_map = {
'.html': 'text/html',
'.css': 'text/css',
'.js': 'application/javascript',
'.json': 'application/json',
'.mp4': 'video/mp4',
'.webm': 'video/webm',
'.png': 'image/png',
'.jpg': 'image/jpeg',
'.jpeg': 'image/jpeg',
'.gif': 'image/gif',
'.svg': 'image/svg+xml',
'.ico': 'image/x-icon',
'': 'application/octet-stream',
}
if __name__ == '__main__':
port = int(sys.argv[1]) if len(sys.argv) > 1 else 8000
server = HTTPServer(('localhost', port), CORSRequestHandler)
print(f'\n Visual Reasoning Playground')
print(f' ===========================')
print(f' Server running at: http://localhost:{port}')
print(f' CORS enabled for sample video support\n')
print(f' Press Ctrl+C to stop\n')
try:
server.serve_forever()
except KeyboardInterrupt:
print('\nServer stopped.')