|
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() |