File size: 1,579 Bytes
01b5648
 
 
 
 
 
 
95bf8db
9127116
95bf8db
 
 
 
 
 
 
a0a535f
95bf8db
a0a535f
 
 
 
 
 
95bf8db
 
 
 
 
 
a119bc3
01b5648
 
 
 
 
 
 
a119bc3
319c05d
01b5648
 
 
 
 
 
08f49a5
a119bc3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import gradio as gr
from utils import extract_text_from_pdf, simple_clause_split
from model import classify_clauses
from report import generate_pdf
from salesforce_stub import send_to_salesforce

# Initialize Gradio interface
def analyze_contract(file):
    tmp_path = file.name
    text = extract_text_from_pdf(tmp_path)
    clauses = simple_clause_split(text)
    results = classify_clauses(clauses)

    overall_score = sum(r['risk_score'] for r in results) / len(results) if results else 0
    report_path = generate_pdf(results, overall_score)

    highlight_output = ""
    for r in results:
        color = (
            "red" if r['risk_level'] == "High" else
            "orange" if r['risk_level'] == "Medium" else
            "green"
        )
        highlight_output += f"<div style='color:{color}'><b>{r['risk_level']}</b>: {r['clause']}</div><br>"

    send_to_salesforce({
        "clauses": results,
        "overall_score": overall_score
    })

    return f"Overall Risk Score: {overall_score:.2f}", highlight_output, report_path

# Create Gradio Interface
iface = gr.Interface(
    fn=analyze_contract,
    inputs=gr.File(label="Upload Contract PDF"),
    outputs=[
        gr.Textbox(label="Overall Risk Score"),
        gr.HTML(label="Clause Risk Highlight"),
        gr.File(label="Download Risk Report (PDF)")
    ],
    title="📜 Contract Risk Heatmap Generator",
    description="Upload a contract and get clause-level risk scores with heatmap-style highlights."
)

# Ensure the Gradio app starts properly
if __name__ == "__main__":
    iface.launch()