Satya Karthik R commited on
Commit
9d5329a
·
1 Parent(s): c70a443

Add application file

Browse files
Files changed (2) hide show
  1. app.py +31 -0
  2. requirements.txt +0 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # backend/app.py
2
+ from flask import Flask, request, jsonify
3
+ from flask_cors import CORS
4
+ from model import DualModelDetector
5
+ from PIL import Image
6
+
7
+ app = Flask(__name__)
8
+ CORS(app, resources={r"/api/*": {"origins": "*"}})
9
+
10
+ # Initialize the Dual Expert
11
+ detector = DualModelDetector()
12
+
13
+ @app.route('/api/predict', methods=['POST'])
14
+ def predict():
15
+ if 'image' not in request.files:
16
+ return jsonify({'error': 'No image uploaded'}), 400
17
+
18
+ file = request.files['image']
19
+
20
+ try:
21
+ image = Image.open(file.stream)
22
+ # Returns the combined analysis
23
+ result = detector.predict(image)
24
+ return jsonify(result)
25
+
26
+ except Exception as e:
27
+ print(f"Server Error: {e}")
28
+ return jsonify({'error': str(e)}), 500
29
+
30
+ if __name__ == '__main__':
31
+ app.run(host='0.0.0.0', port=5000, debug=True)
requirements.txt ADDED
Binary file (1.32 kB). View file