bluuebunny commited on
Commit
3e261a2
·
1 Parent(s): b210a83

added sample app and requirements

Browse files
Files changed (2) hide show
  1. app.py +29 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Import required libraries
2
+ import gradio as gr # For interface
3
+ from sentence_transformers import SentenceTransformer # For embedding the text
4
+ import torch # For gpu
5
+
6
+ # Make the app device agnostic
7
+ device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
8
+
9
+ # Load a pretrained Sentence Transformer model
10
+ model = SentenceTransformer("all-MiniLM-L6-v2").to(device)
11
+
12
+ # Function that does the embedding
13
+ def predict(input_text):
14
+
15
+ # Calculate embeddings by calling model.encode()
16
+ embeddings = model.encode(input_text)
17
+
18
+ return embeddings
19
+
20
+ # Gradio app interface
21
+ gradio_app = gr.Interface(
22
+ predict,
23
+ inputs="text",
24
+ outputs="text",
25
+ title="Embeddings"
26
+ )
27
+
28
+ if __name__ == "__main__":
29
+ gradio_app.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ transformers
2
+ torch
3
+ sentence-transformers