Spaces:
Running
Running
from flask import Flask, request, jsonify | |
from flask_cors import CORS | |
from detect import predict_image_bytes | |
import logging | |
app = Flask(__name__) | |
# Cho phép mọi origin; bạn có thể thay '*' bằng domain cụ thể nếu muốn | |
CORS(app, resources={r"/predict": {"origins": "*"}}) | |
def predict(): | |
try: | |
img_file = request.files['file'] | |
result = predict_image_bytes(img_file.read()) | |
logging.info(f"Detected objects: {result}") | |
return jsonify({"objects": result}) | |
except Exception as e: | |
logging.error(f"Error catched while detecting: {str(e)}") | |
return jsonify({"error": str(e)}), 500 | |
if __name__ == '__main__': | |
app.run(host='0.0.0.0', port=7860, debug=True) | |