Spaces:
Running
Running
File size: 842 Bytes
a5cc7a0 4632e96 c44dddd a5cc7a0 ef16b6d c44dddd a5cc7a0 0551a11 a5cc7a0 c44dddd a5cc7a0 0551a11 |
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 |
from sentence_transformers import SentenceTransformer
import gradio as gr
import update_packages
import numpy as np
# Load the pre-trained model
embedding_model = SentenceTransformer('all-MiniLM-L6-v2')
# Define the function to process requests
def generate_embeddings(chunks):
embeddings = embedding_model.encode(chunks, convert_to_tensor=False)
shape = embeddings.shape
return embeddings.tolist(), shape # Convert numpy array to list
# Define the Gradio interface
interface = gr.Interface(
fn=generate_embeddings,
inputs=gr.Textbox(lines=5, placeholder="Enter text chunks here...", type="list"),
outputs=[gr.JSON(label="Embeddings"), gr.Label(label="Shape")],
title="Sentence Transformer Embeddings",
description="Generate embeddings for input text chunks."
)
# Launch the Gradio app
interface.launch()
|