app.py
CHANGED
|
@@ -4,25 +4,38 @@ from transformers import pipeline
|
|
| 4 |
classifier = pipeline(
|
| 5 |
"text-generation",
|
| 6 |
model="AtrriJi/smolified-risk-clause-classifier",
|
| 7 |
-
device=-1
|
| 8 |
)
|
| 9 |
|
| 10 |
def classify(clause):
|
|
|
|
| 11 |
prompt = f"""
|
| 12 |
-
Classify the legal clause into
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
Clause:
|
| 16 |
{clause}
|
| 17 |
"""
|
| 18 |
|
| 19 |
-
|
| 20 |
prompt,
|
| 21 |
max_new_tokens=100,
|
| 22 |
do_sample=False
|
| 23 |
)[0]["generated_text"]
|
| 24 |
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
demo = gr.Interface(
|
| 28 |
fn=classify,
|
|
|
|
| 4 |
classifier = pipeline(
|
| 5 |
"text-generation",
|
| 6 |
model="AtrriJi/smolified-risk-clause-classifier",
|
| 7 |
+
device=-1
|
| 8 |
)
|
| 9 |
|
| 10 |
def classify(clause):
|
| 11 |
+
|
| 12 |
prompt = f"""
|
| 13 |
+
Classify the legal clause into one of:
|
| 14 |
+
Payment Terms, Intellectual Property, Confidentiality,
|
| 15 |
+
Termination, Indemnification, Force Majeure,
|
| 16 |
+
Governing Law, Warranty, Limitation of Liability,
|
| 17 |
+
Dispute Resolution.
|
| 18 |
+
|
| 19 |
+
Also predict risk level: Low, Medium, or High.
|
| 20 |
+
|
| 21 |
+
Return ONLY JSON like:
|
| 22 |
+
{{"category": "...", "risk_level": "..."}}
|
| 23 |
|
| 24 |
Clause:
|
| 25 |
{clause}
|
| 26 |
"""
|
| 27 |
|
| 28 |
+
result = classifier(
|
| 29 |
prompt,
|
| 30 |
max_new_tokens=100,
|
| 31 |
do_sample=False
|
| 32 |
)[0]["generated_text"]
|
| 33 |
|
| 34 |
+
# Remove prompt part
|
| 35 |
+
clean_output = result[len(prompt):].strip()
|
| 36 |
+
|
| 37 |
+
return clean_output
|
| 38 |
+
|
| 39 |
|
| 40 |
demo = gr.Interface(
|
| 41 |
fn=classify,
|