|
import gradio as gr |
|
from transformers import AutoModel, AutoTokenizer |
|
|
|
|
|
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() |
|
|