codeblacks commited on
Commit
a5cc7a0
·
verified ·
1 Parent(s): e22c41f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -0
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sentence_transformers import SentenceTransformer
2
+ import gradio as gr
3
+
4
+ # Load the pre-trained model
5
+ embedding_model = SentenceTransformer('all-MiniLM-L6-v2')
6
+
7
+ # Define the function to process requests
8
+ def generate_embeddings(chunks):
9
+ embeddings = embedding_model.encode(chunks, convert_to_tensor=True)
10
+ return embeddings.tolist() # Convert tensor to list for Gradio
11
+
12
+ # Define the Gradio interface
13
+ iface = gr.Interface(
14
+ fn=generate_embeddings,
15
+ inputs=gr.inputs.Textbox(lines=5, placeholder="Enter text chunks here..."),
16
+ outputs=gr.outputs.JSON(),
17
+ title="Sentence Transformer Embeddings",
18
+ description="Generate embeddings for input text chunks."
19
+ )
20
+
21
+ # Launch the Gradio app
22
+ if __name__ == "__main__":
23
+ iface.launch()