Spaces:
Running
Running
derek-thomas
commited on
Commit
·
a7eec35
1
Parent(s):
2935fa6
Init commit
Browse files- .gitignore +1 -0
- app.py +29 -0
- requirements.txt +1 -0
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
.idea
|
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import List
|
| 2 |
+
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import spaces
|
| 5 |
+
from sentence_transformers import SentenceTransformer
|
| 6 |
+
|
| 7 |
+
model = SentenceTransformer("nomic-ai/nomic-embed-text-v1", trust_remote_code=True, device='cuda')
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
@spaces.GPU
|
| 11 |
+
def embed(documents: List[str]):
|
| 12 |
+
embeddings = []
|
| 13 |
+
for document in documents:
|
| 14 |
+
embeddings.append(model.encode(document))
|
| 15 |
+
return embeddings
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
with gr.Blocks() as app:
|
| 19 |
+
# Create an input text box
|
| 20 |
+
text_input = gr.Textbox(label="Enter text to embed")
|
| 21 |
+
|
| 22 |
+
# Create an output component to display the embedding
|
| 23 |
+
output = gr.JSON(label="Text Embedding")
|
| 24 |
+
|
| 25 |
+
# When the input text is submitted, call the embedding function and display the output
|
| 26 |
+
text_input.submit(embed, inputs=text_input, outputs=output)
|
| 27 |
+
|
| 28 |
+
if __name__ == '__main__':
|
| 29 |
+
app.queue().launch(server_name="0.0.0.0", show_error=True, server_port=7860)
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
sentence_transformers==2.6.0
|