fraudTech commited on
Commit
d4e6332
·
1 Parent(s): 54cb8b8
Files changed (1) hide show
  1. app.py +119 -0
app.py CHANGED
@@ -391,6 +391,67 @@ def proxy_math_discover():
391
  return jsonify(data), resp.status_code
392
 
393
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
394
  # ============================================================
395
  # SESSION LEMMAS (LIST/CLEAR)
396
  # ============================================================
@@ -481,6 +542,64 @@ def proxy_session_export():
481
  return jsonify(data), resp.status_code
482
 
483
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
484
  @app.route("/session/promote", methods=["POST"])
485
  @jwt_required()
486
  def proxy_session_promote():
 
391
  return jsonify(data), resp.status_code
392
 
393
 
394
+ # ============================================================
395
+ # INGESTION (DOCUMENTS → SESSION STAGING)
396
+ # ============================================================
397
+ @app.route("/ingest/arxiv", methods=["POST"])
398
+ @jwt_required()
399
+ def proxy_ingest_arxiv():
400
+ if HF_TOKEN is None:
401
+ return jsonify({"ok": False, "error": "HF_TOKEN not configured"}), 500
402
+
403
+ try:
404
+ payload = request.get_json(force=True) or {}
405
+ except Exception:
406
+ return jsonify({"ok": False, "error": "Invalid JSON"}), 400
407
+
408
+ try:
409
+ resp = requests.post(
410
+ f"{BACKEND_BASE}/ingest/arxiv",
411
+ json=payload,
412
+ headers={"Authorization": f"Bearer {HF_TOKEN}"},
413
+ timeout=600,
414
+ )
415
+ except Exception as e:
416
+ return jsonify({"ok": False, "error": f"Gateway request failed: {e}"}), 502
417
+
418
+ try:
419
+ data = resp.json()
420
+ except ValueError:
421
+ return jsonify({"ok": False, "error": f"Backend returned non-JSON: {resp.text[:200]}"}), 502
422
+
423
+ return jsonify(data), resp.status_code
424
+
425
+
426
+ @app.route("/ingest/story", methods=["POST"])
427
+ @jwt_required()
428
+ def proxy_ingest_story():
429
+ if HF_TOKEN is None:
430
+ return jsonify({"ok": False, "error": "HF_TOKEN not configured"}), 500
431
+
432
+ try:
433
+ payload = request.get_json(force=True) or {}
434
+ except Exception:
435
+ return jsonify({"ok": False, "error": "Invalid JSON"}), 400
436
+
437
+ try:
438
+ resp = requests.post(
439
+ f"{BACKEND_BASE}/ingest/story",
440
+ json=payload,
441
+ headers={"Authorization": f"Bearer {HF_TOKEN}"},
442
+ timeout=300,
443
+ )
444
+ except Exception as e:
445
+ return jsonify({"ok": False, "error": f"Gateway request failed: {e}"}), 502
446
+
447
+ try:
448
+ data = resp.json()
449
+ except ValueError:
450
+ return jsonify({"ok": False, "error": f"Backend returned non-JSON: {resp.text[:200]}"}), 502
451
+
452
+ return jsonify(data), resp.status_code
453
+
454
+
455
  # ============================================================
456
  # SESSION LEMMAS (LIST/CLEAR)
457
  # ============================================================
 
542
  return jsonify(data), resp.status_code
543
 
544
 
545
+ @app.route("/session/docs", methods=["POST"])
546
+ @jwt_required()
547
+ def proxy_session_docs():
548
+ if HF_TOKEN is None:
549
+ return jsonify({"ok": False, "error": "HF_TOKEN not configured"}), 500
550
+
551
+ try:
552
+ payload = request.get_json(force=True) or {}
553
+ except Exception:
554
+ return jsonify({"ok": False, "error": "Invalid JSON"}), 400
555
+
556
+ try:
557
+ resp = requests.post(
558
+ f"{BACKEND_BASE}/session/docs",
559
+ json=payload,
560
+ headers={"Authorization": f"Bearer {HF_TOKEN}"},
561
+ timeout=60,
562
+ )
563
+ except Exception as e:
564
+ return jsonify({"ok": False, "error": f"Gateway request failed: {e}"}), 502
565
+
566
+ try:
567
+ data = resp.json()
568
+ except ValueError:
569
+ return jsonify({"ok": False, "error": f"Backend returned non-JSON: {resp.text[:200]}"}), 502
570
+
571
+ return jsonify(data), resp.status_code
572
+
573
+
574
+ @app.route("/session/rollback", methods=["POST"])
575
+ @jwt_required()
576
+ def proxy_session_rollback():
577
+ if HF_TOKEN is None:
578
+ return jsonify({"ok": False, "error": "HF_TOKEN not configured"}), 500
579
+
580
+ try:
581
+ payload = request.get_json(force=True) or {}
582
+ except Exception:
583
+ return jsonify({"ok": False, "error": "Invalid JSON"}), 400
584
+
585
+ try:
586
+ resp = requests.post(
587
+ f"{BACKEND_BASE}/session/rollback",
588
+ json=payload,
589
+ headers={"Authorization": f"Bearer {HF_TOKEN}"},
590
+ timeout=60,
591
+ )
592
+ except Exception as e:
593
+ return jsonify({"ok": False, "error": f"Gateway request failed: {e}"}), 502
594
+
595
+ try:
596
+ data = resp.json()
597
+ except ValueError:
598
+ return jsonify({"ok": False, "error": f"Backend returned non-JSON: {resp.text[:200]}"}), 502
599
+
600
+ return jsonify(data), resp.status_code
601
+
602
+
603
  @app.route("/session/promote", methods=["POST"])
604
  @jwt_required()
605
  def proxy_session_promote():