File size: 2,229 Bytes
d545986
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import gradio as gr
import time
from utils import (
    extract_text_from_pdf,
    summarize_text,
    generate_pdf,
    extract_fields_from_summary,
    send_to_salesforce
)

def process_and_summarize(file):
    start_time = time.time()
    try:
        text = extract_text_from_pdf(file)
        char_count = len(text)
        summary = summarize_text(text)
        fields = extract_fields_from_summary(summary)
        sf_response = send_to_salesforce(fields)
        pdf_path = generate_pdf(summary)

        return summary, pdf_path, char_count, round(time.time() - start_time, 2), fields, sf_response

    except Exception as e:
        return f"Error: {str(e)}", None, 0, 0.0, {}, {}

iface = gr.Interface(
    fn=process_and_summarize,
    inputs=gr.File(label="๐Ÿ“„ Upload Contract (PDF)"),
    outputs=[
        gr.Textbox(label="๐Ÿ“ Contract Summary", lines=15, elem_id="summary-box"),
        gr.File(label="๐Ÿ“ฅ Download PDF Summary"),
        gr.Number(label="๐Ÿงฎ Character Count"),
        gr.Number(label="โฑ๏ธ Processing Time (s)"),
        gr.JSON(label="๐Ÿ“ค Fields Sent to Salesforce"),
        gr.JSON(label="๐Ÿ“ฅ Salesforce Response"),
        gr.HTML(
            """
            <button onclick="printSummary()" style='margin-top:10px; padding:10px 20px; font-size:16px;'>๐Ÿ–จ๏ธ Print Summary</button>
            <script>
            function printSummary() {
                const summary = document.querySelector("#summary-box textarea").value;
                const win = window.open('', '', 'height=700,width=800');
                win.document.write('<html><head><title>Contract Summary</title></head><body>');
                win.document.write('<pre style="font-family: Arial; font-size: 14px;">' + summary + '</pre>');
                win.document.write('</body></html>');
                win.document.close();
                win.focus();
                win.print();
                win.close();
            }
            </script>
            """
        )
    ],
    title="๐Ÿง  AI Contract Summarizer + Salesforce",
    description="Upload a contract to summarize, download, print, and sync with Salesforce.",
    allow_flagging="never"
)

if __name__ == "__main__":
    iface.launch()