madoss commited on
Commit
9a26bab
·
1 Parent(s): bea0c91

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -28
app.py CHANGED
@@ -3,17 +3,16 @@ import logging
3
 
4
  import datasets
5
  import gradio as gr
6
- import sentence_transformers
7
 
8
  logging.disable(logging.CRITICAL)
9
 
10
- model = sentence_transformers.SentenceTransformer(
11
- "dangvantuan/sentence-camembert-large", device="cpu")
12
 
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",
@@ -39,36 +38,20 @@ def search(query, k=3):
39
  return results
40
 
41
  iface = gr.Interface(
42
- fn=search,
43
  inputs=[
44
- gr.inputs.Textbox(
45
- label="Query", placeholder="Type in a search query...", lines=3
46
- ),
47
- gr.inputs.Number(
48
- label="K",
49
- default=3,
50
- description="Number of results to return",
51
- ),
52
  ],
53
  outputs=[
54
- gr.outputs.Label(
55
- label="Result 1", type="auto", default="Search results will appear here."
56
- ),
57
- gr.outputs.Label(
58
- label="Result 2", type="auto", default=""
59
- ),
60
- gr.outputs.Link(
61
- label="Result 3", type="auto", default=""
62
- ),
63
  ],
64
  title="Camembert and Faiss-powered Search Engine",
65
  description="Search through a dataset using Camembert and Faiss",
66
- theme="default",
67
  layout="vertical",
68
- allow_flagging=False,
69
- allow_screenshot=False,
70
- allow_share=True,
71
- allow_download=False
72
  )
73
 
74
  iface.launch()
 
3
 
4
  import datasets
5
  import gradio as gr
 
6
 
7
  logging.disable(logging.CRITICAL)
8
 
9
+ model_name = "dangvantuan/sentence-camembert-large"
10
+ model = gradio.load(model_name)
11
 
12
+ dataset = datasets.load_dataset("json", data_files=["./data/dataset.json"], split="train")
13
  dataset.load_faiss_index("embeddings", "index.faiss")
14
 
15
+ def search(query, k):
16
  query_embedding = model.encode(query)
17
  _, retrieved_examples = dataset.get_nearest_examples(
18
  "embeddings",
 
38
  return results
39
 
40
  iface = gr.Interface(
41
+ search,
42
  inputs=[
43
+ gr.inputs.Textbox(label="Query"),
44
+ gr.inputs.Number(label="K", default=3, min_value=1, max_value=10),
 
 
 
 
 
 
45
  ],
46
  outputs=[
47
+ gr.outputs.Textbox(label="Result 1"),
48
+ gr.outputs.Textbox(label="Result 2"),
49
+ gr.outputs.Textbox(label="Result 3"),
 
 
 
 
 
 
50
  ],
51
  title="Camembert and Faiss-powered Search Engine",
52
  description="Search through a dataset using Camembert and Faiss",
53
+ theme="light",
54
  layout="vertical",
 
 
 
 
55
  )
56
 
57
  iface.launch()