File size: 824 Bytes
a1043e7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from typing import List
import torch

import gradio as gr
import spaces
from sentence_transformers import SentenceTransformer

device = torch.device("cpu")
model = SentenceTransformer("cnmoro/snowflake-arctic-embed-m-v2.0-cpu", device=device, trust_remote_code=True)

@spaces.GPU
def embed(document: str):
    return model.encode(document)


with gr.Blocks() as app:
    # Create an input text box
    text_input = gr.Textbox(label="Enter text to embed")

    # Create an output component to display the embedding
    output = gr.JSON(label="Text Embedding")

    # When the input text is submitted, call the embedding function and display the output
    text_input.submit(embed, inputs=text_input, outputs=output)

if __name__ == '__main__':
    app.queue().launch(server_name="0.0.0.0", show_error=True, server_port=7860)