-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
42 lines (31 loc) · 1.12 KB
/
app.py
File metadata and controls
42 lines (31 loc) · 1.12 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
import os
from flask import Flask, request, jsonify, send_from_directory
from flask_cors import CORS
from detector import ObjectDetector
app = Flask(__name__, static_folder='static', static_url_path='')
CORS(app)
# Initialize detector
detector = ObjectDetector()
@app.route('/')
def index():
return app.send_static_file('index.html')
@app.route('/detect', methods=['POST'])
def detect():
if 'image' not in request.files:
return jsonify({'error': 'No image provided'}), 400
file = request.files['image']
if file.filename == '':
return jsonify({'error': 'No image selected'}), 400
try:
# Read file into memory
image_bytes = file.read()
# Get threshold from form data or default
threshold = float(request.form.get('confidence', 0.25))
# Process image
results = detector.process_image(image_bytes, threshold)
return jsonify(results)
except Exception as e:
print(f"Error processing image: {e}")
return jsonify({'error': str(e)}), 500
if __name__ == '__main__':
app.run(debug=True, port=5000)