Spaces:
Configuration error
Configuration error
| import gradio as gr | |
| import base64 | |
| import tempfile | |
| 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 | |
| def analyze_contract(file): | |
| # Hugging Face provides `file.name` (a path to the uploaded 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 | |
| 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. Powered by Hugging Face Transformers." | |
| ) | |
| if __name__ == "__main__": | |
| iface.launch() | |