Sampathkumarbandaru's picture
Upload 5 files
d545986 verified
raw
history blame
2.23 kB
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()