countbigger commited on
Commit
9b0c38f
·
verified ·
1 Parent(s): e450675

Create app.py

Browse files

made the app.py first edition

Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from sentence_transformers import SentenceTransformer
3
+ import torch
4
+ import spaces
5
+
6
+ # Load model on startup (fits in 16GB RAM)
7
+ model = SentenceTransformer('perplexity-ai/pplx-embed-v1-4b')
8
+
9
+ @spaces.cpu # Use CPU for free tier
10
+ def embed_text(texts):
11
+ if isinstance(texts, str):
12
+ texts = [texts]
13
+ embeddings = model.encode(texts, normalize_embeddings=True)
14
+ return embeddings.tolist()
15
+
16
+ # Gradio interface with API support
17
+ demo = gr.Interface(
18
+ fn=embed_text,
19
+ inputs=gr.Textbox(label="Enter text(s), one per line", lines=3, placeholder="Your text here..."),
20
+ outputs=gr.Textbox(label="Embeddings (JSON)", lines=10),
21
+ title="pplx-embed-v1-4b API",
22
+ description="Free embedding inference. Use /embed endpoint via API."
23
+ )
24
+
25
+ if __name__ == "__main__":
26
+ demo.launch()