codeblacks commited on
Commit
c44dddd
·
verified ·
1 Parent(s): 4632e96

Update app.py

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