Spaces:
Running
Running
# app.py | |
import gradio as gr | |
import os | |
from utils.parser import parse_file | |
from utils.summarizer import summarize_text | |
from utils.metadata import extract_metadata | |
from utils.risk_detector import detect_risks | |
from utils.fallback_suggester import suggest_fallback | |
from utils.translator import translate_text | |
def handle_input(file, raw_text): | |
if file is not None: | |
content = parse_file(file.name) | |
elif raw_text.strip() != "": | |
content = raw_text | |
else: | |
return "Please upload a contract or paste text.", "", {}, [], "", "" | |
return content, "", {}, [], "", "" | |
with gr.Blocks(title="SYNCLM β AI Contract Intelligence Demo") as demo: | |
gr.Markdown( | |
""" | |
<div style="font-size: 28px; font-weight: bold; margin-bottom: 10px;"> | |
π Innovation Meets Intelligence | |
</div> | |
<div style="font-size: 18px; line-height: 1.5;"> | |
Upload a contract or paste the text. SYNCLM will analyze, summarize, extract metadata, detect risks, suggest fallback clauses, and even translate key sections. | |
</div> | |
""" | |
) | |
with gr.Row(): | |
file_input = gr.File(label="π Upload Contract (.pdf, .docx, .txt)", file_types=[".pdf", ".docx", ".txt"]) | |
text_input = gr.Textbox(label="βοΈ Or Paste Contract Text", lines=10, placeholder="Paste contract text here...") | |
parse_btn = gr.Button("π Parse Contract") | |
contract_display = gr.Textbox(label="π Parsed Contract", lines=20) | |
with gr.Row(): | |
summarize_btn = gr.Button("π Summarize") | |
metadata_btn = gr.Button("π Extract Metadata") | |
risk_btn = gr.Button("β οΈ Detect Risks") | |
fallback_btn = gr.Button("π‘οΈ Suggest Fallback") | |
translate_btn = gr.Button("π Translate to Portuguese") | |
summary_output = gr.Textbox(label="π Executive Summary", lines=6) | |
metadata_output = gr.JSON(label="π Extracted Metadata") | |
risk_output = gr.Dataframe(label="π© Risky Clauses", headers=["Clause Type", "Confidence"], datatype=["str", "number"]) | |
fallback_output = gr.Textbox(label="π‘ Suggested Fallback Clause", lines=4) | |
translation_output = gr.Textbox(label="π Portuguese Translation", lines=10) | |
# Action Buttons | |
parse_btn.click( | |
fn=handle_input, | |
inputs=[file_input, text_input], | |
outputs=[contract_display, summary_output, metadata_output, risk_output, fallback_output, translation_output] | |
) | |
summarize_btn.click(fn=summarize_text, inputs=[contract_display], outputs=[summary_output]) | |
metadata_btn.click(fn=extract_metadata, inputs=[contract_display], outputs=[metadata_output]) | |
risk_btn.click(fn=detect_risks, inputs=[contract_display], outputs=[risk_output]) | |
fallback_btn.click(fn=suggest_fallback, inputs=[contract_display], outputs=[fallback_output]) | |
translate_btn.click(fn=translate_text, inputs=[contract_display], outputs=[translation_output]) | |
if __name__ == "__main__": | |
demo.launch() | |