Spaces:
Sleeping
Sleeping
| 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) |