Spaces:
Sleeping
Sleeping
File size: 941 Bytes
5ed0967 97a4dbc 5ed0967 97a4dbc 5ed0967 97a4dbc 5ed0967 |
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 |
import gradio as gr
from sentence_transformers import SentenceTransformer
# Load the Nomic embedding model
model = SentenceTransformer("nomic-ai/nomic-embed-text-v1", trust_remote_code=True)
def get_embedding(text):
"""Generate an embedding for the input text using Nomic encoder."""
if not text.strip():
return "Please provide some text."
# Generate embedding
embedding = model.encode([text])[0] # Get the first (and only) embedding
# Return embedding as list (more user-friendly in the UI)
return embedding.tolist()
# Create Gradio interface
interface = gr.Interface(
fn=get_embedding,
inputs=gr.Textbox(lines=5, placeholder="Enter text to embed..."),
outputs=gr.JSON(),
title="Text Embedding with Nomic Encoder",
description="Enter text to get its embedding vector using the Nomic Encoder model."
)
# Launch the interface
if __name__ == "__main__":
interface.launch() |