Upload 2 files
Browse files- ocr_server.py +5 -35
ocr_server.py
CHANGED
|
@@ -345,45 +345,15 @@ def solve():
|
|
| 345 |
|
| 346 |
@app.route('/feedback', methods=['POST'])
|
| 347 |
def feedback():
|
| 348 |
-
"""
|
|
|
|
|
|
|
|
|
|
| 349 |
data = request.get_json(force=True)
|
| 350 |
rejected = check_request_token(data)
|
| 351 |
if rejected:
|
| 352 |
return rejected
|
| 353 |
-
|
| 354 |
-
label = data.get('label', '').strip().upper()
|
| 355 |
-
|
| 356 |
-
if not image_b64 or not label or len(label) < 4:
|
| 357 |
-
return jsonify({'ok': False, 'error': 'Missing image or label'}), 400
|
| 358 |
-
|
| 359 |
-
try:
|
| 360 |
-
# Strip data URI prefix if present
|
| 361 |
-
if ',' in image_b64 and image_b64.startswith('data:'):
|
| 362 |
-
image_b64 = image_b64.split(',', 1)[1]
|
| 363 |
-
image_bytes = base64.b64decode(image_b64)
|
| 364 |
-
filename = f"{label}_{int(time.time()*1000)}.png"
|
| 365 |
-
|
| 366 |
-
# Upload directly to HF Dataset repo (non-blocking)
|
| 367 |
-
persisted = False
|
| 368 |
-
if hf_api:
|
| 369 |
-
def upload():
|
| 370 |
-
try:
|
| 371 |
-
hf_api.upload_file(
|
| 372 |
-
path_or_fileobj=image_bytes,
|
| 373 |
-
path_in_repo=f"images/{filename}",
|
| 374 |
-
repo_id=DATASET_REPO,
|
| 375 |
-
repo_type='dataset',
|
| 376 |
-
)
|
| 377 |
-
except Exception as e:
|
| 378 |
-
print(f"HF upload error: {e}")
|
| 379 |
-
threading.Thread(target=upload, daemon=True).start()
|
| 380 |
-
persisted = True
|
| 381 |
-
|
| 382 |
-
# Count from HF repo (cached, updated periodically)
|
| 383 |
-
count = _get_dataset_count()
|
| 384 |
-
return jsonify({'ok': True, 'saved': filename, 'total_samples': count, 'persisted': persisted})
|
| 385 |
-
except Exception as e:
|
| 386 |
-
return jsonify({'ok': False, 'error': str(e)}), 500
|
| 387 |
|
| 388 |
|
| 389 |
# Cached dataset count (avoid hitting HF API on every request)
|
|
|
|
| 345 |
|
| 346 |
@app.route('/feedback', methods=['POST'])
|
| 347 |
def feedback():
|
| 348 |
+
"""Training-data collection is finished (dataset full at 10k) — accept and discard.
|
| 349 |
+
|
| 350 |
+
Kept as a no-op so deployed extensions calling it fire-and-forget don't error.
|
| 351 |
+
"""
|
| 352 |
data = request.get_json(force=True)
|
| 353 |
rejected = check_request_token(data)
|
| 354 |
if rejected:
|
| 355 |
return rejected
|
| 356 |
+
return jsonify({'ok': True, 'saved': None, 'total_samples': _get_dataset_count(), 'persisted': False})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 357 |
|
| 358 |
|
| 359 |
# Cached dataset count (avoid hitting HF API on every request)
|