codeblacks's picture
Create app.py
718e3b3 verified
raw
history blame
738 Bytes
import gradio as gr
from sentence_transformers import SentenceTransformer
# Load the pre-trained model
model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
def get_embeddings(sentences):
# Get embeddings for the input sentences
embeddings = model.encode(sentences)
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.JSON(), # Output component
title="Sentence Embeddings", # Interface title
description="Enter sentences to get their embeddings." # Description
)
# Launch the interface
interface.launch()