Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModel
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
tokenizer = AutoTokenizer.from_pretrained("law-ai/InLegalBERT")
|
| 6 |
+
model = AutoModel.from_pretrained("law-ai/InLegalBERT")
|
| 7 |
+
|
| 8 |
+
def encode(text):
|
| 9 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
|
| 10 |
+
outputs = model(**inputs)
|
| 11 |
+
cls_embedding = outputs.last_hidden_state[:, 0, :].squeeze().detach().numpy()
|
| 12 |
+
return str(cls_embedding[:10]) # แสดงเฉพาะ 10 ค่าแรก
|
| 13 |
+
|
| 14 |
+
demo = gr.Interface(fn=encode, inputs="text", outputs="text")
|
| 15 |
+
demo.launch()
|