Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,26 +2,30 @@ import gradio as gr
|
|
| 2 |
from sentence_transformers import SentenceTransformer
|
| 3 |
import torch
|
| 4 |
|
| 5 |
-
# Load model with trust_remote_code=True for perplexity models
|
| 6 |
model = SentenceTransformer(
|
| 7 |
'perplexity-ai/pplx-embed-v1-4b',
|
| 8 |
trust_remote_code=True,
|
| 9 |
-
device='cpu'
|
| 10 |
)
|
| 11 |
|
| 12 |
-
def embed_text(
|
| 13 |
-
if
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
| 17 |
|
| 18 |
demo = gr.Interface(
|
| 19 |
fn=embed_text,
|
| 20 |
-
inputs=gr.Textbox(
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
)
|
| 25 |
|
| 26 |
if __name__ == "__main__":
|
| 27 |
-
demo.launch()
|
|
|
|
| 2 |
from sentence_transformers import SentenceTransformer
|
| 3 |
import torch
|
| 4 |
|
|
|
|
| 5 |
model = SentenceTransformer(
|
| 6 |
'perplexity-ai/pplx-embed-v1-4b',
|
| 7 |
trust_remote_code=True,
|
| 8 |
+
device='cpu'
|
| 9 |
)
|
| 10 |
|
| 11 |
+
def embed_text(text):
|
| 12 |
+
if not text or text.strip() == "":
|
| 13 |
+
return "Please enter single text input"
|
| 14 |
+
|
| 15 |
+
embedding = model.encode([text], normalize_embeddings=True)[0]
|
| 16 |
+
return embedding.tolist()
|
| 17 |
|
| 18 |
demo = gr.Interface(
|
| 19 |
fn=embed_text,
|
| 20 |
+
inputs=gr.Textbox(
|
| 21 |
+
label="Single Text Input",
|
| 22 |
+
lines=1,
|
| 23 |
+
placeholder="enter here..."
|
| 24 |
+
),
|
| 25 |
+
outputs=gr.Textbox(label="Embedding (JSON)", lines=10),
|
| 26 |
+
title="text-to-embedding",
|
| 27 |
+
description="simple text-to-embedding, using pplx-embed-v1-4b"
|
| 28 |
)
|
| 29 |
|
| 30 |
if __name__ == "__main__":
|
| 31 |
+
demo.launch(share=False, show_error=True)
|