app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
classifier = pipeline(
|
| 5 |
+
"text-generation",
|
| 6 |
+
model="AtrriJi/smolified-risk-clause-classifier",
|
| 7 |
+
device=-1 # force CPU
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
def classify(clause):
|
| 11 |
+
prompt = f"""
|
| 12 |
+
Classify the legal clause into a category and risk level.
|
| 13 |
+
Return JSON with keys category and risk_level.
|
| 14 |
+
|
| 15 |
+
Clause:
|
| 16 |
+
{clause}
|
| 17 |
+
"""
|
| 18 |
+
|
| 19 |
+
output = classifier(
|
| 20 |
+
prompt,
|
| 21 |
+
max_new_tokens=100,
|
| 22 |
+
do_sample=False
|
| 23 |
+
)[0]["generated_text"]
|
| 24 |
+
|
| 25 |
+
return output
|
| 26 |
+
|
| 27 |
+
demo = gr.Interface(
|
| 28 |
+
fn=classify,
|
| 29 |
+
inputs="text",
|
| 30 |
+
outputs="text",
|
| 31 |
+
title="Risk Clause Classifier"
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
demo.launch()
|