File size: 1,498 Bytes
d545986 d5b8dbb d545986 d5b8dbb |
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 |
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(
"""
๐จ๏ธ Print Summary
"""
)
],
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() |