gabor1 commited on
Commit
2e00785
·
verified ·
1 Parent(s): 9f53bc9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -2
app.py CHANGED
@@ -14,7 +14,9 @@ def rerank(query, docs_text):
14
  with torch.no_grad():
15
  scores = model(**inputs).logits.squeeze(-1)
16
  results = sorted(zip(docs, scores.tolist()), key=lambda x: x[1], reverse=True)
17
- return "\n\n".join([f"Score: {score:.4f}\n{doc}" for doc, score in results])
 
 
18
 
19
  # Create API-ready Interface
20
  iface = gr.Interface(
@@ -23,7 +25,7 @@ iface = gr.Interface(
23
  gr.Textbox(label="Query", lines=1),
24
  gr.Textbox(label="Documents (one per line)", lines=10)
25
  ],
26
- outputs="text",
27
  title="BGE Reranker v2 M3",
28
  description="Rerank a list of documents based on a search query using BGE v2 M3."
29
  )
 
14
  with torch.no_grad():
15
  scores = model(**inputs).logits.squeeze(-1)
16
  results = sorted(zip(docs, scores.tolist()), key=lambda x: x[1], reverse=True)
17
+
18
+ # Return structured JSON array
19
+ return [{"score": round(score, 4), "document": doc} for doc, score in results]
20
 
21
  # Create API-ready Interface
22
  iface = gr.Interface(
 
25
  gr.Textbox(label="Query", lines=1),
26
  gr.Textbox(label="Documents (one per line)", lines=10)
27
  ],
28
+ outputs="json",
29
  title="BGE Reranker v2 M3",
30
  description="Rerank a list of documents based on a search query using BGE v2 M3."
31
  )