Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -13,7 +13,7 @@ model = sentence_transformers.SentenceTransformer(
|
|
13 |
dataset = datasets.load_dataset("json", data_files=["./dataset.json"], split="train")
|
14 |
dataset.load_faiss_index("embeddings", "index.faiss")
|
15 |
|
16 |
-
def search(query, k):
|
17 |
query_embedding = model.encode(query)
|
18 |
_, retrieved_examples = dataset.get_nearest_examples(
|
19 |
"embeddings",
|
@@ -38,21 +38,54 @@ def search(query, k):
|
|
38 |
results.append(result)
|
39 |
return results
|
40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
iface = gr.Interface(
|
42 |
-
search,
|
43 |
inputs=[
|
44 |
-
gr.inputs.Textbox(
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
],
|
47 |
outputs=[
|
48 |
-
gr.outputs.
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
],
|
52 |
title="Camembert and Faiss-powered Search Engine",
|
53 |
description="Search through a dataset using Camembert and Faiss",
|
54 |
-
theme="
|
55 |
layout="vertical",
|
|
|
|
|
|
|
|
|
|
|
56 |
)
|
57 |
|
58 |
iface.launch()
|
|
|
13 |
dataset = datasets.load_dataset("json", data_files=["./dataset.json"], split="train")
|
14 |
dataset.load_faiss_index("embeddings", "index.faiss")
|
15 |
|
16 |
+
def search(query, k=3):
|
17 |
query_embedding = model.encode(query)
|
18 |
_, retrieved_examples = dataset.get_nearest_examples(
|
19 |
"embeddings",
|
|
|
38 |
results.append(result)
|
39 |
return results
|
40 |
|
41 |
+
# Add custom styles to the interface
|
42 |
+
styles = gr.Styles(
|
43 |
+
button_color="white",
|
44 |
+
label_font="Arial",
|
45 |
+
label_font_size=18,
|
46 |
+
label_color="black",
|
47 |
+
input_font="Arial",
|
48 |
+
input_font_size=18,
|
49 |
+
input_color="black",
|
50 |
+
output_font="Arial",
|
51 |
+
output_font_size=18,
|
52 |
+
output_color="black",
|
53 |
+
full_width=True,
|
54 |
+
background="#f2f2f2",
|
55 |
+
)
|
56 |
+
|
57 |
iface = gr.Interface(
|
58 |
+
fn=search,
|
59 |
inputs=[
|
60 |
+
gr.inputs.Textbox(
|
61 |
+
label="Query", placeholder="Type in a search query...", lines=3
|
62 |
+
),
|
63 |
+
gr.inputs.Number(
|
64 |
+
label="K",
|
65 |
+
default=3,
|
66 |
+
description="Number of results to return",
|
67 |
+
),
|
68 |
],
|
69 |
outputs=[
|
70 |
+
gr.outputs.Label(
|
71 |
+
label="Result 1", type="auto", default="Search results will appear here."
|
72 |
+
),
|
73 |
+
gr.outputs.Label(
|
74 |
+
label="Result 2", type="auto", default=""
|
75 |
+
),
|
76 |
+
gr.outputs.Link(
|
77 |
+
label="Result 3", type="auto", default=""
|
78 |
+
),
|
79 |
],
|
80 |
title="Camembert and Faiss-powered Search Engine",
|
81 |
description="Search through a dataset using Camembert and Faiss",
|
82 |
+
theme="default",
|
83 |
layout="vertical",
|
84 |
+
allow_flagging=False,
|
85 |
+
allow_screenshot=False,
|
86 |
+
allow_share=True,
|
87 |
+
allow_download=False,
|
88 |
+
style=styles,
|
89 |
)
|
90 |
|
91 |
iface.launch()
|