File size: 858 Bytes
3f7f963
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
29
30
31
32
import gradio as gr
from typing import TypedDict

class Hit(TypedDict):
  cid: str
  score: float
  text: str

demo: Optional[gr.Interface] = None  # Assign your gradio demo to this variable
return_type = List[Hit]
## YOUR_CODE_STARTS_HERE
def search_sciq(query: str) -> List[Hit]:
    results = bm25_retriever.retrieve(query)

    # Format the output to match the List[Hit] structure
    hits = []
    for cid, score in results.items():
        index = bm25_retriever.index.cid2docid[cid]
        text = bm25_retriever.index.doc_texts[index]
        hits.append(Hit(cid=cid, score=score, text=text))

    return hits

# Set up the Gradio interface
demo = gr.Interface(
    fn=search_sciq,
    inputs=gr.Textbox(label="Enter your query"),
    outputs=gr.JSON(label="Top 10 Results"),
    description="BM25 Search Engine Demo on SciQ Dataset"
)
demo.launch()