Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForMaskedLM, pipeline
|
3 |
+
|
4 |
+
model_id = "law-ai/InLegalBERT"
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
6 |
+
model = AutoModelForMaskedLM.from_pretrained(model_id)
|
7 |
+
|
8 |
+
nlp = pipeline("fill-mask", model=model, tokenizer=tokenizer)
|
9 |
+
|
10 |
+
def explain_law(text):
|
11 |
+
try:
|
12 |
+
results = nlp(text)
|
13 |
+
return results[0]['sequence']
|
14 |
+
except Exception as e:
|
15 |
+
return f"Error: {str(e)}"
|
16 |
+
|
17 |
+
demo = gr.Interface(
|
18 |
+
fn=explain_law,
|
19 |
+
inputs=gr.Textbox(label="Enter Legal Sentence with [MASK] for completion"),
|
20 |
+
outputs=gr.Textbox(label="Legal Output"),
|
21 |
+
title="InLegalBERT Legal Engine",
|
22 |
+
allow_flagging="never"
|
23 |
+
)
|
24 |
+
|
25 |
+
demo.launch()
|