derek-thomas HF staff commited on
Commit
a7eec35
1 Parent(s): 2935fa6

Init commit

Browse files
Files changed (3) hide show
  1. .gitignore +1 -0
  2. app.py +29 -0
  3. 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