uslap commited on
Commit
3e4a8c7
·
verified ·
1 Parent(s): b8f6c2d

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +28 -14
app.py CHANGED
@@ -45,12 +45,33 @@ DESCRIPTION = """
45
  """
46
 
47
 
48
- NOT_FOUND_MARKERS = [
49
- "HYPOTHESIS:",
50
- "No entries found",
51
- "not found in index",
52
- "CANDIDATES:",
53
- ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
  def run_query(query: str) -> str:
56
  if not query or not query.strip():
@@ -73,14 +94,7 @@ def run_query(query: str) -> str:
73
  if not out:
74
  return f"[stderr]\n{err}" if err else "(no output)"
75
 
76
- # Block hypothesis / unconfirmed output — only confirmed DB data shown.
77
- # Direction: Allah's Arabic → downstream. Hypothesis mode runs the
78
- # reverse (downstream → candidate AA roots) without a confirmed chain.
79
- first_line = out.splitlines()[0] if out else ""
80
- if any(m in first_line for m in NOT_FOUND_MARKERS):
81
- return f"Not found in DB: '{query.strip()}'\n\nOnly confirmed entries are shown here.\nRun locally with the full engine for hypothesis mode."
82
-
83
- return out
84
 
85
  except subprocess.TimeoutExpired:
86
  return "Query timed out (30s)."
 
45
  """
46
 
47
 
48
+ def strip_hypothesis(text: str, query: str) -> str:
49
+ """Remove any HYPOTHESIS block from output.
50
+ Only confirmed DB data is shown on the public Space.
51
+ Direction: Allah's Arabic → downstream. ALWAYS.
52
+ Hypothesis mode reverses this without a confirmed chain — blocked here.
53
+ """
54
+ lines = text.splitlines()
55
+ clean = []
56
+ in_hypothesis = False
57
+
58
+ for line in lines:
59
+ if "HYPOTHESIS:" in line or "CANDIDATES:" in line:
60
+ in_hypothesis = True
61
+ if in_hypothesis:
62
+ continue
63
+ clean.append(line)
64
+
65
+ result = "\n".join(clean).strip()
66
+
67
+ if not result:
68
+ return (
69
+ f"Not found in DB: '{query}'\n\n"
70
+ "Only confirmed entries are shown here.\n"
71
+ "Run locally with the full engine for hypothesis mode."
72
+ )
73
+ return result
74
+
75
 
76
  def run_query(query: str) -> str:
77
  if not query or not query.strip():
 
94
  if not out:
95
  return f"[stderr]\n{err}" if err else "(no output)"
96
 
97
+ return strip_hypothesis(out, query.strip())
 
 
 
 
 
 
 
98
 
99
  except subprocess.TimeoutExpired:
100
  return "Query timed out (30s)."