Sampathkumarbandaru's picture
Update app.py
d5b8dbb verified
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()