File size: 748 Bytes
a5cc7a0
 
a7357eb
a5cc7a0
 
 
 
18feec4
 
 
a5cc7a0
 
0551a11
18feec4
 
 
 
 
a5cc7a0
 
18feec4
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from sentence_transformers import SentenceTransformer
import gradio as gr
import torch

# Load the pre-trained model
embedding_model = SentenceTransformer('all-MiniLM-L6-v2')

def get_embeddings(sentences):
    embeddings = model.encode(sentences, convert_to_tensor=True)
    return embeddings.tolist()

# Define the Gradio interface
interface = gr.Interface(
    fn=get_embeddings,  # Function to call
    inputs=gr.Textbox(lines=2, placeholder="Enter sentences here, one per line"),  # Input component
    outputs=gr.Image(label="Embeddings", image_formatter=plot_embeddings)
    title="Sentence Embeddings",  # Interface title
    description="Enter sentences to get their embeddings."  # Description
)

# Launch the interface
interface.launch()