File size: 1,761 Bytes
c3c72a1
b181032
c3c72a1
 
 
527716a
c3c72a1
b181032
c3c72a1
 
 
77a44bd
 
 
 
 
 
 
 
 
c3c72a1
 
 
 
 
77a44bd
 
 
 
 
 
c3c72a1
 
 
 
 
77a44bd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c3c72a1
77a44bd
c3c72a1
 
 
 
 
 
 
 
 
 
2c5c4f1
c3c72a1
 
ac9848c
c3c72a1
2c5c4f1
 
b19469c
c3c72a1
b181032
 
 
 
b6abe36
c3c72a1
8915dbd
c3c72a1
 
 
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import os

import streamlit as st
import streamlit.components.v1 as components
from datasets import load_dataset
from pyserini.search.lucene import LuceneSearcher

st.set_page_config(page_title="IMDB Search", layout="wide")

st.sidebar.markdown(
    """
    <style>
    .aligncenter {
        text-align: center;
        font-weight: bold;
        font-size: 28px;
    }
    </style>
    <p class="aligncenter">IMDB Search</p>
    """,
    unsafe_allow_html=True,
)

st.sidebar.markdown(
    """
    <style>
    .aligncenter {
        text-align: center;
    }
    </style>
    """,
    unsafe_allow_html=True,
)

query = st.sidebar.text_input(label="Search query", value="")

footer = """
    <style>
    .footer {
        position: fixed;
        left: 0;
        bottom: 0;
        width: 100%;
        background-color: white;
        color: black;
        text-align: center;
    }
    </style>
    <div class="footer">
    <p>
    Powered by <a href="https://huggingface.co/" >HuggingFace 🤗</a> and <a href="https://github.com/castorini/pyserini" >Pyserini 🦆</a>
    </p>
    </div>
"""

st.sidebar.markdown(footer, unsafe_allow_html=True)


searcher = LuceneSearcher("index")
ds = load_dataset("imdb", split="train")


def search(query):
    hits = searcher.search(query, k=10)
    results = ds.select([int(hit.docid) for hit in hits])
    return results["text"]


if st.sidebar.button("Search 🔍"):
    results = search(query)
    results_html = ""
    for result in results:
        results_html += result + "<br><br><hr><br><br>"
    rendered_results = f"""
        <div id="searchresultsarea">
            {results_html}
        </div>
    """

    components.html(
        rendered_results,
        height=800,
        scrolling=True,
    )