-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
45 lines (36 loc) · 1.38 KB
/
app.py
File metadata and controls
45 lines (36 loc) · 1.38 KB
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
"""
Semantic Search Interface
This script implements a Gradio interface for performing semantic search
on a given text. It allows users to input an encoder model,
a search query, and a main text, and retrieves the top five paragraphs
that share similar meaning.
Usage:
1. Set the desired valuess.
2. Run the script.
3. The Gradio interface will be launched, allowing you to interact with
the semantic search functionality.
"""
import gradio as gr
from src import read_string_from_file, semantic_search
# Inputs
text_example = read_string_from_file("./example/text_example.txt")
model_name = gr.Textbox(
value="all-mpnet-base-v2", label="Encoder model (See the code)"
) # find the list here: https://www.sbert.net/docs/pretrained_models.html
mode = gr.Dropdown(
choices=["Sentence", "Paragraph"], value="Sentence", label="Search mode"
)
searching_for = gr.Textbox(value="IoT in healthcare", label="Semantic search for")
text = gr.Textbox(value=text_example, label="Your main text")
# outputs
out = gr.Textbox(
value="Press submit", label="Top five results that share close meanings"
)
if __name__ == "__main__":
iface = gr.Interface(
fn=semantic_search,
title="Semantic Search",
inputs=[model_name, mode, searching_for, text],
outputs=[out],
)
iface.launch(share=False) # share=False to share with others