Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from transformers import AutoTokenizer, AutoModel
|
| 4 |
+
|
| 5 |
+
def get_embeddings(text):
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained("GroNLP/bert-base-dutch-cased")
|
| 7 |
+
model = AutoModel.from_pretrained("GroNLP/bert-base-dutch-cased", output_hidden_states=True)
|
| 8 |
+
sent = str(text)
|
| 9 |
+
encoded = tokenizer.encode_plus(sent, return_tensors="pt")
|
| 10 |
+
with torch.no_grad():
|
| 11 |
+
output = model(**encoded)
|
| 12 |
+
|
| 13 |
+
states = output.hidden_states
|
| 14 |
+
return states
|
| 15 |
+
|
| 16 |
+
iface = gr.Interface(fn=get_embeddings,inputs="text",outputs="text")
|
| 17 |
+
iface.launch()
|