Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoModel, AutoTokenizer
|
3 |
+
|
4 |
+
# Load a small CPU model for text to vector processing
|
5 |
+
model_name = "sentence-transformers/all-MiniLM-L6-v2"
|
6 |
+
model = AutoModel.from_pretrained(model_name)
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
+
|
9 |
+
def text_to_vector(text):
|
10 |
+
inputs = tokenizer(text, return_tensors="pt")
|
11 |
+
outputs = model(**inputs)
|
12 |
+
vector = outputs.pooler_output.detach().numpy()[0]
|
13 |
+
return vector
|
14 |
+
|
15 |
+
demo = gr.Interface(
|
16 |
+
fn=text_to_vector,
|
17 |
+
inputs=gr.Textbox(label="Enter text"),
|
18 |
+
outputs=gr.Textbox(label="Text Vector"),
|
19 |
+
title="Text to Vector",
|
20 |
+
description="This demo uses a small CPU model to convert text to vector."
|
21 |
+
)
|
22 |
+
|
23 |
+
demo.launch()
|