File size: 716 Bytes
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 |
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):
inputs = tokenizer(text, return_tensors="pt")
outputs = model(**inputs)
vector = outputs.pooler_output.detach().numpy()[0]
return vector
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()
|