File size: 807 Bytes
9b0c38f
 
 
 
ad5cac4
 
 
3783441
ad5cac4
9b0c38f
3783441
 
 
 
 
 
9b0c38f
 
 
3783441
 
 
 
 
 
 
 
9b0c38f
 
 
3783441
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
30
31
import gradio as gr
from sentence_transformers import SentenceTransformer
import torch

model = SentenceTransformer(
    'perplexity-ai/pplx-embed-v1-4b',
    trust_remote_code=True,
    device='cpu'
)

def embed_text(text):
    if not text or text.strip() == "":
        return "Please enter single text input"
    
    embedding = model.encode([text], normalize_embeddings=True)[0]
    return embedding.tolist()

demo = gr.Interface(
    fn=embed_text,
    inputs=gr.Textbox(
        label="Single Text Input", 
        lines=1,
        placeholder="enter here..."
    ),
    outputs=gr.Textbox(label="Embedding (JSON)", lines=10),
    title="text-to-embedding",
    description="simple text-to-embedding, using pplx-embed-v1-4b"
)

if __name__ == "__main__":
    demo.launch(share=False, show_error=True)