Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from sentence_transformers import SentenceTransformer
|
| 3 |
+
|
| 4 |
+
# Load the pre-trained model
|
| 5 |
+
model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
|
| 6 |
+
|
| 7 |
+
def get_embeddings(sentences):
|
| 8 |
+
# Get embeddings for the input sentences
|
| 9 |
+
embeddings = model.encode(sentences)
|
| 10 |
+
return embeddings.tolist()
|
| 11 |
+
|
| 12 |
+
# Define the Gradio interface
|
| 13 |
+
interface = gr.Interface(
|
| 14 |
+
fn=get_embeddings, # Function to call
|
| 15 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter sentences here, one per line"), # Input component
|
| 16 |
+
outputs=gr.JSON(), # Output component
|
| 17 |
+
title="Sentence Embeddings", # Interface title
|
| 18 |
+
description="Enter sentences to get their embeddings." # Description
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
# Launch the interface
|
| 22 |
+
interface.launch()
|