nlpWeb / app.py
Sophia Koehler
Add application file
3f7f963
raw
history blame
858 Bytes
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()