Spaces:
Sleeping
Sleeping
File size: 952 Bytes
e90224d eccd7f3 e90224d eccd7f3 494e283 eccd7f3 7074f5d e90224d eccd7f3 8dd6a37 eccd7f3 e90224d 7074f5d e90224d 8dd6a37 e90224d 8dd6a37 e90224d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
import gradio as gr
from sentence_transformers import CrossEncoder
# Load and optimize the model
model = CrossEncoder(
"jinaai/jina-reranker-v1-tiny-en",
trust_remote_code=True
)
# Function to rerank documents
def rerank(query, documents):
documents = documents.split("&&&") # Use special delimiter
inputs = [[query, doc] for doc in documents if doc.strip()]
scores = model.predict(inputs)
ranked_docs = sorted(zip(documents, scores), key=lambda x: x[1], reverse=True)
return [{"document": doc, "score": round(score, 4)} for doc, score in ranked_docs]
# Gradio Interface
iface = gr.Interface(
fn=rerank,
inputs=["text", gr.Textbox(label="Documents (Separate with &&&)", placeholder="Doc1 &&& Doc2 &&& Doc3")],
outputs="json",
title="JinaAI v2 Reranker API (Optimized)",
description="Enter a query and documents (separated by '&&&'). The model will rank them based on relevance.",
)
iface.launch()
|