Try to get markdown content to load
Browse files- backend/runner/app.py +22 -4
backend/runner/app.py
CHANGED
|
@@ -190,9 +190,10 @@ def list_work_images(work_id: str):
|
|
| 190 |
|
| 191 |
full_work_id = f"W{work_id}"
|
| 192 |
print(f"π list_work_images called with work_id: {full_work_id}")
|
| 193 |
-
|
|
|
|
| 194 |
if not img_dir.is_dir():
|
| 195 |
-
print(f"β
|
| 196 |
return jsonify([])
|
| 197 |
|
| 198 |
files = sorted(
|
|
@@ -418,17 +419,27 @@ def get_work(id: str):
|
|
| 418 |
------------
|
| 419 |
sentence : original-English sentence text (URL-encoded)
|
| 420 |
"""
|
|
|
|
| 421 |
work = works.get(id)
|
| 422 |
if work is None:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 423 |
return jsonify({}), 404
|
| 424 |
|
| 425 |
# ---------------- context lookup ----------------
|
| 426 |
sentence = request.args.get("sentence", "").strip()
|
| 427 |
context = ""
|
| 428 |
if sentence:
|
|
|
|
| 429 |
md_path = get_markdown_dir() / id / f"{id}.md"
|
|
|
|
| 430 |
if md_path.is_file():
|
|
|
|
| 431 |
content = md_path.read_text(encoding="utf-8", errors="ignore")
|
|
|
|
| 432 |
import re
|
| 433 |
from difflib import SequenceMatcher
|
| 434 |
|
|
@@ -460,6 +471,12 @@ def get_work(id: str):
|
|
| 460 |
if not context and best_ratio >= 0.55:
|
| 461 |
context = best_para
|
| 462 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 463 |
payload = {**work, "context": context}
|
| 464 |
return jsonify(payload)
|
| 465 |
|
|
@@ -590,9 +607,10 @@ def heatmap():
|
|
| 590 |
@app.route("/marker/<work_id>/<path:filename>", methods=["GET"])
|
| 591 |
def serve_marker_image(work_id: str, filename: str):
|
| 592 |
"""
|
| 593 |
-
Static file server for data/marker_output/<work_id
|
| 594 |
"""
|
| 595 |
-
|
|
|
|
| 596 |
img_path = img_dir / filename
|
| 597 |
mime, _ = guess_type(filename)
|
| 598 |
if not img_path.exists():
|
|
|
|
| 190 |
|
| 191 |
full_work_id = f"W{work_id}"
|
| 192 |
print(f"π list_work_images called with work_id: {full_work_id}")
|
| 193 |
+
work_dir = get_markdown_dir() / full_work_id
|
| 194 |
+
img_dir = work_dir / "images"
|
| 195 |
if not img_dir.is_dir():
|
| 196 |
+
print(f"β Images directory not found: {img_dir}")
|
| 197 |
return jsonify([])
|
| 198 |
|
| 199 |
files = sorted(
|
|
|
|
| 419 |
------------
|
| 420 |
sentence : original-English sentence text (URL-encoded)
|
| 421 |
"""
|
| 422 |
+
print(f"π get_work called with id: {id}")
|
| 423 |
work = works.get(id)
|
| 424 |
if work is None:
|
| 425 |
+
print(f"β Work not found: {id}")
|
| 426 |
+
print(f"π Available works: {len(works)} total")
|
| 427 |
+
if len(works) > 0:
|
| 428 |
+
sample_keys = list(works.keys())[:5]
|
| 429 |
+
print(f"π Sample work IDs: {sample_keys}")
|
| 430 |
return jsonify({}), 404
|
| 431 |
|
| 432 |
# ---------------- context lookup ----------------
|
| 433 |
sentence = request.args.get("sentence", "").strip()
|
| 434 |
context = ""
|
| 435 |
if sentence:
|
| 436 |
+
print(f"π Looking for context for sentence: {sentence[:100]}...")
|
| 437 |
md_path = get_markdown_dir() / id / f"{id}.md"
|
| 438 |
+
print(f"π Markdown path: {md_path}")
|
| 439 |
if md_path.is_file():
|
| 440 |
+
print(f"β
Markdown file found, reading content...")
|
| 441 |
content = md_path.read_text(encoding="utf-8", errors="ignore")
|
| 442 |
+
print(f"π Content length: {len(content)} characters")
|
| 443 |
import re
|
| 444 |
from difflib import SequenceMatcher
|
| 445 |
|
|
|
|
| 471 |
if not context and best_ratio >= 0.55:
|
| 472 |
context = best_para
|
| 473 |
|
| 474 |
+
else:
|
| 475 |
+
print(f"β Markdown file not found: {md_path}")
|
| 476 |
+
else:
|
| 477 |
+
print(f"π No sentence provided for context lookup")
|
| 478 |
+
|
| 479 |
+
print(f"π Final context length: {len(context)} characters")
|
| 480 |
payload = {**work, "context": context}
|
| 481 |
return jsonify(payload)
|
| 482 |
|
|
|
|
| 607 |
@app.route("/marker/<work_id>/<path:filename>", methods=["GET"])
|
| 608 |
def serve_marker_image(work_id: str, filename: str):
|
| 609 |
"""
|
| 610 |
+
Static file server for data/marker_output/<work_id>/images/<filename>
|
| 611 |
"""
|
| 612 |
+
work_dir = get_markdown_dir() / work_id
|
| 613 |
+
img_dir = work_dir / "images"
|
| 614 |
img_path = img_dir / filename
|
| 615 |
mime, _ = guess_type(filename)
|
| 616 |
if not img_path.exists():
|