Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,53 +0,0 @@
|
|
| 1 |
-
"""Hugging Face Space: live CPU demo for the exact fixed evidence-graph reranker."""
|
| 2 |
-
import json
|
| 3 |
-
import gradio as gr
|
| 4 |
-
from evidence_graph_reranker import EvidenceGraphReranker
|
| 5 |
-
|
| 6 |
-
_RERANKERS = {}
|
| 7 |
-
EXAMPLE = [
|
| 8 |
-
{"title": "Atlas device", "text": "The Atlas device was launched by Novus Labs in 2025."},
|
| 9 |
-
{"title": "Novus Labs", "text": "Novus Labs was founded by Mira Chen in 2018."},
|
| 10 |
-
{"title": "Orion spacecraft", "text": "The Orion spacecraft is designed for space missions."},
|
| 11 |
-
{"title": "Electronics", "text": "Electronics can be manufactured in many countries."},
|
| 12 |
-
]
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
def demo(query, passages_json, budget, backend):
|
| 16 |
-
try:
|
| 17 |
-
docs = json.loads(passages_json)
|
| 18 |
-
if not isinstance(docs, list) or not 1 <= len(docs) <= 100:
|
| 19 |
-
raise ValueError("Enter a JSON list containing 1–100 passages.")
|
| 20 |
-
if not query.strip():
|
| 21 |
-
raise ValueError("Query cannot be empty.")
|
| 22 |
-
if backend not in _RERANKERS:
|
| 23 |
-
_RERANKERS[backend] = EvidenceGraphReranker(backend=backend, device="cpu", batch_size=16)
|
| 24 |
-
ranked = _RERANKERS[backend].rank(query, docs, k=int(budget))
|
| 25 |
-
table = [
|
| 26 |
-
[i + 1, r["index"], r["title"] or "(untitled)",
|
| 27 |
-
round(r["relevance_score"], 4), round(r["step_score"], 4),
|
| 28 |
-
round(r["directed_link_bonus"], 2)]
|
| 29 |
-
for i, r in enumerate(ranked)
|
| 30 |
-
]
|
| 31 |
-
return table, json.dumps(ranked, indent=2, ensure_ascii=False)
|
| 32 |
-
except Exception as exc:
|
| 33 |
-
return [], json.dumps({"error": str(exc)})
|
| 34 |
-
|
| 35 |
-
with gr.Blocks(title="Evidence-Graph Reranker") as app:
|
| 36 |
-
gr.Markdown("# Evidence-Graph Reranker\nTraining-free, query-conditioned **joint evidence selection** after neural relevance scoring.\n\nA passage's usefulness can rise when it completes a link from a previously selected passage. This demo uses **one fixed graph rule** for every dataset. Model weights are fetched from their original Hugging Face repositories.")
|
| 37 |
-
query = gr.Textbox(label="Query", value="Who founded the company that released the Atlas device?")
|
| 38 |
-
passages = gr.Code(label="Candidate passages (JSON array; optional title)", language="json",
|
| 39 |
-
value=json.dumps(EXAMPLE, indent=2))
|
| 40 |
-
with gr.Row():
|
| 41 |
-
budget = gr.Slider(minimum=1, maximum=10, step=1, value=3, label="Passage budget (k)")
|
| 42 |
-
backend = gr.Dropdown(choices=["cross-encoder", "dense"], value="cross-encoder",
|
| 43 |
-
label="Pretrained neural relevance model")
|
| 44 |
-
go = gr.Button("Select complementary evidence", variant="primary")
|
| 45 |
-
table = gr.Dataframe(headers=["Rank", "Candidate index", "Title", "Neural score", "Selection score", "Link bonus"],
|
| 46 |
-
datatype=["number", "number", "str", "number", "number", "number"],
|
| 47 |
-
label="Selected passages", interactive=False)
|
| 48 |
-
output = gr.Code(label="Full selection JSON", language="json")
|
| 49 |
-
go.click(demo, inputs=[query, passages, budget, backend], outputs=[table, output])
|
| 50 |
-
gr.Markdown("**Interpretation:** `selection_score` is a step-dependent heuristic, not a probability. Gold labels are never used by the selector. Reported benchmarks measure complete evidence coverage, *not* LLM-generated answer accuracy. See `MODEL_CARD.md` for protocols and caveats.")
|
| 51 |
-
|
| 52 |
-
if __name__ == "__main__":
|
| 53 |
-
app.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|