File size: 938 Bytes
c6e8a33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
33
34
35
36
37
import gradio as gr
from module.bible_index import BibleIndex


def query_index(query, testament, top_n):
    _index = BibleIndex(testament)
    items = _index.query(query, top_n=top_n)

    item_list = f"<h2>{query}</h2>"
    item_list += "<ul>"
    for item in items:
        item_list += f"<h3>{item.get('src')}</h3>"
        item_list += f"<li>{item.get('text')}</li>"
    item_list += "</ul>"
    return item_list


demo = gr.Interface(
    query_index,
    [
        gr.Textbox(label="Query text"),
        gr.Radio(["all", "old", "new"], label="Section of the Bible"),
        gr.Slider(0, 10, step=1, label="Top N results"),
    ],
    outputs="html",
    examples=[
        ["What is love", "new", 5],
        ["How old was Adam?", "old", 3],
        ["Who is God?", "all", 7],
    ],
    title="Bible Search Index",
    description="""
        A search index for The Bible using *sentence_transformer*.
    """,
)
demo.launch()