doomsday2004 commited on
Commit
eccd7f3
·
verified ·
1 Parent(s): 0504f27

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -9
app.py CHANGED
@@ -1,18 +1,22 @@
1
  import gradio as gr
2
- from optimum.pipelines import pipeline
3
- from transformers import AutoTokenizer
4
 
5
- # Load ONNX optimized model
6
- model_name = "jinaai/jina-reranker-v2-base-multilingual"
7
- tokenizer = AutoTokenizer.from_pretrained(model_name)
8
- model = pipeline("text-classification", model=model_name, tokenizer=tokenizer, trust_remote_code=True)
 
 
 
 
9
 
10
  # Function to rerank documents
11
  def rerank(query, documents):
12
- documents = documents.split("&&&")
13
  inputs = [[query, doc] for doc in documents if doc.strip()]
14
- scores = model(inputs)
15
- ranked_docs = sorted(zip(documents, [s['score'] for s in scores]), key=lambda x: x[1], reverse=True)
16
  return [{"document": doc, "score": round(score, 4)} for doc, score in ranked_docs]
17
 
18
  # Gradio Interface
 
1
  import gradio as gr
2
+ from sentence_transformers import CrossEncoder
3
+ from fastrag.utils import optimize_model
4
 
5
+ # Load and optimize the model
6
+ model = CrossEncoder(
7
+ "jinaai/jina-reranker-v2-base-multilingual",
8
+ trust_remote_code=True
9
+ )
10
+
11
+ # Apply Intel IPEX optimization (FastRAG)
12
+ model = optimize_model(model, backend="ipex") # ✅ Faster CPU inference
13
 
14
  # Function to rerank documents
15
  def rerank(query, documents):
16
+ documents = documents.split("&&&") # Use special delimiter
17
  inputs = [[query, doc] for doc in documents if doc.strip()]
18
+ scores = model.predict(inputs)
19
+ ranked_docs = sorted(zip(documents, scores), key=lambda x: x[1], reverse=True)
20
  return [{"document": doc, "score": round(score, 4)} for doc, score in ranked_docs]
21
 
22
  # Gradio Interface