chuuuuuuuu commited on
Commit
3f232d0
·
verified ·
1 Parent(s): c227b4b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -0
app.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+ import gradio as gr
3
+ from transformers import AutoTokenizer, AutoModel
4
+ import torch
5
+
6
+ model_name = "BM-K/KoSimCSE-roberta"
7
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+ model = AutoModel.from_pretrained(model_name)
9
+
10
+ def embed(text):
11
+ inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
12
+ with torch.no_grad():
13
+ outputs = model(**inputs)
14
+ embeddings = outputs.last_hidden_state[:, 0]
15
+ return embeddings.tolist()
16
+
17
+ iface = gr.Interface(fn=embed, inputs="text", outputs="text")
18
+ iface.launch()