File size: 925 Bytes
0c07570
 
 
 
 
 
 
 
 
d1f2845
 
 
0c07570
 
 
d1f2845
 
 
0c07570
 
 
 
 
 
 
 
 
 
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
29
import gradio as gr
from transformers import AutoModel, AutoTokenizer

# Load a small CPU model for text to vector processing
model_name = "sentence-transformers/all-MiniLM-L6-v2"
model = AutoModel.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)

def text_to_vector(text):
    """
    Converts text to a vector representation using a pre-trained model.
    """
    inputs = tokenizer(text, return_tensors="pt")
    outputs = model(**inputs)
    vector = outputs.pooler_output.detach().numpy()[0]
    # Convert the vector to a string representation for display
    vector_str = ", ".join([str(x) for x in vector])
    return vector_str

demo = gr.Interface(
    fn=text_to_vector,
    inputs=gr.Textbox(label="Enter text"),
    outputs=gr.Textbox(label="Text Vector"),
    title="Text to Vector",
    description="This demo uses a small CPU model to convert text to vector."
)

demo.launch()