Sophia Koehler commited on
Commit
3f7f963
·
1 Parent(s): f4928ce

Add application file

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from typing import TypedDict
3
+
4
+ class Hit(TypedDict):
5
+ cid: str
6
+ score: float
7
+ text: str
8
+
9
+ demo: Optional[gr.Interface] = None # Assign your gradio demo to this variable
10
+ return_type = List[Hit]
11
+ ## YOUR_CODE_STARTS_HERE
12
+ def search_sciq(query: str) -> List[Hit]:
13
+ results = bm25_retriever.retrieve(query)
14
+
15
+ # Format the output to match the List[Hit] structure
16
+ hits = []
17
+ for cid, score in results.items():
18
+ index = bm25_retriever.index.cid2docid[cid]
19
+ text = bm25_retriever.index.doc_texts[index]
20
+ hits.append(Hit(cid=cid, score=score, text=text))
21
+
22
+ return hits
23
+
24
+ # Set up the Gradio interface
25
+ demo = gr.Interface(
26
+ fn=search_sciq,
27
+ inputs=gr.Textbox(label="Enter your query"),
28
+ outputs=gr.JSON(label="Top 10 Results"),
29
+ description="BM25 Search Engine Demo on SciQ Dataset"
30
+ )
31
+ demo.launch()