OpceanAI commited on
Commit
17072ab
·
verified ·
1 Parent(s): 2b3811b

Upload pasita.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. pasita.py +19 -18
pasita.py CHANGED
@@ -1041,24 +1041,25 @@ def convert_to_markdown(
1041
  ) -> dict[str, Any]:
1042
  if kind == "generic":
1043
  kind = infer_kind(text)
1044
- if skip_model_for_structured and structured_fallback and kind in ("html", "data"):
1045
- candidates = [postprocess(c, text) for c in structured_candidates(text)]
1046
- if not candidates:
1047
- candidates = [postprocess(text, text)]
1048
- best, metrics = rerank_candidates(text, candidates, must, kind)
1049
- return {
1050
- "markdown": candidates[best],
1051
- "candidate_index": best,
1052
- "fallback_used": True,
1053
- "metrics": metrics[best],
1054
- "candidate_metrics": metrics,
1055
- "candidates": candidates,
1056
- "raw_candidates": [],
1057
- "prompt_tokens": 0,
1058
- "max_new_tokens": 0,
1059
- "seconds": 0.0,
1060
- "strategy": {"mode": "structured", "best_index": best, "structured_fallback": True},
1061
- }
 
1062
  result = generate_candidates(model, tokenizer, text, **gen_kwargs)
1063
  candidates = list(result.candidates)
1064
  fallback_start = len(candidates)
 
1041
  ) -> dict[str, Any]:
1042
  if kind == "generic":
1043
  kind = infer_kind(text)
1044
+ if skip_model_for_structured and structured_fallback and kind in ("html", "data"):
1045
+ candidates = [postprocess(c, text) for c in structured_candidates(text)]
1046
+ if not candidates:
1047
+ candidates = [postprocess(text, text)]
1048
+ best, metrics = rerank_candidates(text, candidates, must, kind)
1049
+ return {
1050
+ "markdown": candidates[best],
1051
+ "candidate_index": best,
1052
+ "fallback_used": True,
1053
+ "route": "structured",
1054
+ "metrics": metrics[best],
1055
+ "candidate_metrics": metrics,
1056
+ "candidates": candidates,
1057
+ "raw_candidates": [],
1058
+ "prompt_tokens": 0,
1059
+ "max_new_tokens": 0,
1060
+ "seconds": 0.0,
1061
+ "strategy": {"mode": "structured", "best_index": best, "structured_fallback": True, "route": "structured"},
1062
+ }
1063
  result = generate_candidates(model, tokenizer, text, **gen_kwargs)
1064
  candidates = list(result.candidates)
1065
  fallback_start = len(candidates)