koesan commited on
Commit
da8478b
·
verified ·
1 Parent(s): 1efd11c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import os
2
  import cv2
3
  import numpy as np
 
4
  from flask import Flask, request, render_template, jsonify
5
  from werkzeug.utils import secure_filename
6
 
@@ -128,5 +129,35 @@ def predict():
128
  os.remove(filepath)
129
  return jsonify({'error': str(e)}), 500
130
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
  if __name__ == '__main__':
132
  app.run(host='0.0.0.0', port=7860, debug=False)
 
1
  import os
2
  import cv2
3
  import numpy as np
4
+ import base64
5
  from flask import Flask, request, render_template, jsonify
6
  from werkzeug.utils import secure_filename
7
 
 
129
  os.remove(filepath)
130
  return jsonify({'error': str(e)}), 500
131
 
132
+ @app.route('/test-example', methods=['POST'])
133
+ def test_example():
134
+ """Test with example image"""
135
+ try:
136
+ example_path = 'image/20251012_13h56m44s_grim.png'
137
+
138
+ if not os.path.exists(example_path):
139
+ return jsonify({'error': 'Example image not found. Please add 20251012_13h56m44s_grim.png to image/ folder'}), 404
140
+
141
+ print(f"Testing with example file: {example_path}")
142
+
143
+ # Make prediction
144
+ result = predict_image(example_path)
145
+
146
+ # Read and encode image as base64
147
+ with open(example_path, 'rb') as f:
148
+ img_data = f.read()
149
+ img_base64 = base64.b64encode(img_data).decode('utf-8')
150
+ result['image'] = f"data:image/png;base64,{img_base64}"
151
+
152
+ print(f"✓ Example prediction completed: {result['class']}")
153
+
154
+ return jsonify(result)
155
+
156
+ except Exception as e:
157
+ print(f"Error during example prediction: {e}")
158
+ import traceback
159
+ traceback.print_exc()
160
+ return jsonify({'error': str(e)}), 500
161
+
162
  if __name__ == '__main__':
163
  app.run(host='0.0.0.0', port=7860, debug=False)