gr json
Browse files
app.py
CHANGED
|
@@ -1,17 +1,22 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from sentence_transformers
|
| 3 |
|
| 4 |
ce = CrossEncoder("cross-encoder/ms-marco-MiniLM-L6-v2")
|
| 5 |
|
| 6 |
-
def rerank(query,
|
| 7 |
-
|
|
|
|
|
|
|
| 8 |
scores = ce.predict(pairs)
|
| 9 |
-
rows = [[
|
| 10 |
return rows
|
| 11 |
|
| 12 |
iface = gr.Interface(
|
| 13 |
fn=rerank,
|
| 14 |
-
inputs=[
|
|
|
|
|
|
|
|
|
|
| 15 |
outputs=gr.Dataframe(type="array", headers=["doc", "score"]),
|
| 16 |
api_name="rerank"
|
| 17 |
)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from sentence_transformers import CrossEncoder
|
| 3 |
|
| 4 |
ce = CrossEncoder("cross-encoder/ms-marco-MiniLM-L6-v2")
|
| 5 |
|
| 6 |
+
def rerank(query, docs):
|
| 7 |
+
# docs уже list[dict], а не строка
|
| 8 |
+
texts = [d.get("A", str(d)) for d in docs]
|
| 9 |
+
pairs = [[query, txt] for txt in texts]
|
| 10 |
scores = ce.predict(pairs)
|
| 11 |
+
rows = [[txt, float(score)] for txt, score in zip(texts, scores)]
|
| 12 |
return rows
|
| 13 |
|
| 14 |
iface = gr.Interface(
|
| 15 |
fn=rerank,
|
| 16 |
+
inputs=[
|
| 17 |
+
gr.Textbox(label="Query"),
|
| 18 |
+
gr.JSON(label="Docs (JSON array of objects)")
|
| 19 |
+
],
|
| 20 |
outputs=gr.Dataframe(type="array", headers=["doc", "score"]),
|
| 21 |
api_name="rerank"
|
| 22 |
)
|