Spaces:
Runtime error
Runtime error
commit changes
Browse files- app.py +2 -4
- pyserini_wikipedia_kilt_doc.py +32 -0
- requirements.txt +95 -0
- tool_config.json +5 -0
app.py
CHANGED
@@ -1,7 +1,5 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
|
4 |
-
return "Hello " + name + "!!"
|
5 |
-
|
6 |
-
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
7 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from pyserini_wikipedia_kilt_doc import search
|
3 |
|
4 |
+
iface = gr.Interface(fn=search, inputs="text", outputs="text")
|
|
|
|
|
|
|
5 |
iface.launch()
|
pyserini_wikipedia_kilt_doc.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pyserini.search.lucene import LuceneSearcher
|
2 |
+
from transformers import Tool
|
3 |
+
import json
|
4 |
+
|
5 |
+
|
6 |
+
# searcher = LuceneSearcher.from_prebuilt_index('wikipedia-kilt-doc')
|
7 |
+
searcher = LuceneSearcher('index-wikipedia-kilt-doc-20210421-f29307.b8ec8feb654f7aaa86f9901dc6c804a8')
|
8 |
+
|
9 |
+
|
10 |
+
|
11 |
+
def search(query):
|
12 |
+
hits = searcher.search(query, k=1)
|
13 |
+
|
14 |
+
# for i in range(0, 5):
|
15 |
+
# print(f'{i+1:2} {hits[i].docid:15} {hits[i].score:.5f}')
|
16 |
+
|
17 |
+
hit = hits[0]
|
18 |
+
contents = json.loads(hit.raw)['contents']
|
19 |
+
return contents
|
20 |
+
|
21 |
+
class PyseriniWikipediaKiltDoc(Tool):
|
22 |
+
name = "pyserini-wikipedia-kilt-doc"
|
23 |
+
description = (
|
24 |
+
"This is a tool that returns the top 5 results from the Wikipedia KILT index."
|
25 |
+
)
|
26 |
+
|
27 |
+
inputs = ["text"]
|
28 |
+
outputs = ["text"]
|
29 |
+
|
30 |
+
def __call__(self, query: str):
|
31 |
+
return search(query)
|
32 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
appdirs==1.4.4
|
2 |
+
autokey==0.95.10
|
3 |
+
bcc==0.18.0
|
4 |
+
bcrypt==3.1.7
|
5 |
+
blinker==1.4
|
6 |
+
Brlapi==0.8.2
|
7 |
+
Brotli==1.0.9
|
8 |
+
certifi==2020.6.20
|
9 |
+
chardet==4.0.0
|
10 |
+
chrome-gnome-shell==0.0.0
|
11 |
+
click==7.1.2
|
12 |
+
colorama==0.4.4
|
13 |
+
command-not-found==0.3
|
14 |
+
cryptography==3.3.2
|
15 |
+
cupshelpers==1.0
|
16 |
+
dbus-python==1.2.16
|
17 |
+
decorator==4.4.2
|
18 |
+
defer==1.0.6
|
19 |
+
distlib==0.3.1
|
20 |
+
distro==1.5.0
|
21 |
+
distro-info==1.0
|
22 |
+
faiss-cpu==1.7.4
|
23 |
+
filelock==3.0.12
|
24 |
+
gssapi==1.6.12
|
25 |
+
gyp==0.1
|
26 |
+
hidpidaemon==18.4.6
|
27 |
+
httplib2==0.18.1
|
28 |
+
idna==2.10
|
29 |
+
ifaddr==0.1.7
|
30 |
+
importlib-metadata==4.0.1
|
31 |
+
jeepney==0.7.1
|
32 |
+
keyring==23.0.1
|
33 |
+
language-selector==0.1
|
34 |
+
launchpadlib==1.10.13
|
35 |
+
lazr.restfulclient==0.14.2
|
36 |
+
lazr.uri==1.0.5
|
37 |
+
louis==3.18.0
|
38 |
+
lz4==3.1.3+dfsg
|
39 |
+
macaroonbakery==1.3.1
|
40 |
+
more-itertools==4.2.0
|
41 |
+
netaddr==0.8.0
|
42 |
+
netifaces==0.10.9
|
43 |
+
numpy==1.19.5
|
44 |
+
oauthlib==3.1.0
|
45 |
+
olefile==0.46
|
46 |
+
paramiko==2.7.2
|
47 |
+
Pillow==8.1.2
|
48 |
+
pop-transition==1.1.2
|
49 |
+
protobuf==3.12.4
|
50 |
+
py-cpuinfo==5.0.0
|
51 |
+
py3dns==3.2.1
|
52 |
+
pycairo==1.16.2
|
53 |
+
pycups==2.0.1
|
54 |
+
pydbus==0.6.0
|
55 |
+
Pygments==2.7.1
|
56 |
+
PyGObject==3.40.1
|
57 |
+
pyinotify==0.9.6
|
58 |
+
PyJWT==1.7.1
|
59 |
+
pykerberos==1.1.14
|
60 |
+
pymacaroons==0.13.0
|
61 |
+
PyNaCl==1.4.0
|
62 |
+
PyOpenGL==3.1.5
|
63 |
+
pyRFC3339==1.1
|
64 |
+
python-apt===2.2.1pop0-1628521831-21.10-5dbe6cf
|
65 |
+
python-dateutil==2.8.1
|
66 |
+
python-debian===0.1.39ubuntu1
|
67 |
+
python-lzo==1.12
|
68 |
+
python-xlib==0.29
|
69 |
+
pytz==2021.1
|
70 |
+
pyxdg==0.27
|
71 |
+
PyYAML==5.3.1
|
72 |
+
rencode==1.0.6
|
73 |
+
repolib==1.5.2
|
74 |
+
repoman==1.4.0
|
75 |
+
requests==2.25.1
|
76 |
+
screen-resolution-extra==0.0.0
|
77 |
+
SecretStorage==3.3.1
|
78 |
+
sessioninstaller==0.0.0
|
79 |
+
setproctitle==1.2.1
|
80 |
+
simplejson==3.17.2
|
81 |
+
six==1.16.0
|
82 |
+
ssh-import-id==5.11
|
83 |
+
systemd-python==234
|
84 |
+
ubuntu-advantage-tools==27.8
|
85 |
+
ubuntu-drivers-common==0.0.0
|
86 |
+
ufw==0.36.1
|
87 |
+
uritools==3.0.0
|
88 |
+
urllib3==1.26.5
|
89 |
+
virtualenv==20.4.6+ds
|
90 |
+
wadllib==1.3.5
|
91 |
+
xdg==5
|
92 |
+
xkit==0.0.0
|
93 |
+
xpra==3.0.13
|
94 |
+
zeroconf==0.26.1
|
95 |
+
zipp==1.0.0
|
tool_config.json
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"description": "This is a tool that returns the top 5 results from the Wikipedia KILT index.",
|
3 |
+
"name": "pyserini_wikipedia_kilt_doc",
|
4 |
+
"tool_class": "pyserini_wikipedia_kilt_doc.PyseriniWikipediaKiltDoc"
|
5 |
+
}
|