from sentence_transformers import SentenceTransformer
import gradio as gr
import ast

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

def get_embeddings(sentences):
    chunks = ast.literal_eval(sentences)
    embeddings = model.encode(chunks, 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.JSON(),
    outputs=gr.Textbox(label="Embeddings"),
    title="Sentence Embeddings",  # Interface title
    description="Enter sentences to get their embeddings."  # Description
)

# Launch the interface
interface.launch()