Spaces:
Sleeping
Sleeping
Noshitha
commited on
Commit
·
a24806d
1
Parent(s):
17d01d5
Add application file
Browse files- app.py +30 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
| 3 |
+
from peft import PeftModel
|
| 4 |
+
|
| 5 |
+
# Load base + LoRA fine-tuned model
|
| 6 |
+
base_model = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
|
| 7 |
+
adapter_model = "Noshitha98/TinyLlama-ToS-Finetuned"
|
| 8 |
+
|
| 9 |
+
tokenizer = AutoTokenizer.from_pretrained(base_model)
|
| 10 |
+
model = AutoModelForCausalLM.from_pretrained(base_model)
|
| 11 |
+
model = PeftModel.from_pretrained(model, adapter_model)
|
| 12 |
+
|
| 13 |
+
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
| 14 |
+
|
| 15 |
+
def check_clause(text):
|
| 16 |
+
# Instruction prompt for anomaly detection
|
| 17 |
+
prompt = f"Detect unusual or risky clauses in this contract:\n\n{text}\n\nResponse:"
|
| 18 |
+
output = pipe(prompt, max_length=512, do_sample=False)[0]["generated_text"]
|
| 19 |
+
return output
|
| 20 |
+
|
| 21 |
+
# Gradio UI
|
| 22 |
+
iface = gr.Interface(
|
| 23 |
+
fn=check_clause,
|
| 24 |
+
inputs=gr.Textbox(lines=8, placeholder="Paste contract clause here..."),
|
| 25 |
+
outputs="text",
|
| 26 |
+
title="Contract Clause Checker",
|
| 27 |
+
description="Paste contract text to detect unusual or anomalous clauses using TinyLlama-ToS-Finetuned."
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
iface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
transformers
|
| 2 |
+
peft
|
| 3 |
+
torch
|
| 4 |
+
gradio
|