Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import os
|
| 5 |
+
from utils.parser import parse_file
|
| 6 |
+
from utils.summarizer import summarize_text
|
| 7 |
+
from utils.metadata import extract_metadata
|
| 8 |
+
from utils.risk_detector import detect_risks
|
| 9 |
+
from utils.fallback_suggester import suggest_fallback
|
| 10 |
+
from utils.translator import translate_text
|
| 11 |
+
|
| 12 |
+
DEEPL_API_KEY = os.getenv("DEEPL_API_KEY")
|
| 13 |
+
|
| 14 |
+
def handle_input(file, raw_text):
|
| 15 |
+
if file is not None:
|
| 16 |
+
content = parse_file(file.name)
|
| 17 |
+
elif raw_text.strip() != "":
|
| 18 |
+
content = raw_text
|
| 19 |
+
else:
|
| 20 |
+
return "Please upload a contract or paste text.", "", "", "", ""
|
| 21 |
+
|
| 22 |
+
return content, "", "", "", ""
|
| 23 |
+
|
| 24 |
+
with gr.Blocks(title="SYNCLM β AI Contract Intelligence Demo") as demo:
|
| 25 |
+
gr.Markdown("# π€ SYNCLM β AI Contract Intelligence Demo")
|
| 26 |
+
gr.Markdown("Upload a contract or paste text. Then run intelligent actions below.")
|
| 27 |
+
|
| 28 |
+
with gr.Row():
|
| 29 |
+
file_input = gr.File(label="π Upload Contract (.pdf, .docx, .txt)", file_types=[".pdf", ".docx", ".txt"])
|
| 30 |
+
text_input = gr.Textbox(label="βοΈ Or Paste Contract Text", lines=10, placeholder="Paste contract text here...")
|
| 31 |
+
|
| 32 |
+
parse_btn = gr.Button("π Parse Contract")
|
| 33 |
+
contract_display = gr.Textbox(label="π Parsed Contract", lines=15)
|
| 34 |
+
|
| 35 |
+
with gr.Row():
|
| 36 |
+
summarize_btn = gr.Button("π Summarize")
|
| 37 |
+
metadata_btn = gr.Button("π
Extract Metadata")
|
| 38 |
+
risk_btn = gr.Button("β οΈ Detect Risks")
|
| 39 |
+
fallback_btn = gr.Button("π‘οΈ Suggest Fallback")
|
| 40 |
+
translate_btn = gr.Button("π Translate")
|
| 41 |
+
|
| 42 |
+
summary_output = gr.Textbox(label="π Executive Summary", lines=5)
|
| 43 |
+
metadata_output = gr.JSON(label="π Extracted Metadata")
|
| 44 |
+
risk_output = gr.Dataframe(label="π© Risky Clauses", headers=["Clause Type", "Confidence"], datatype=["str", "number"])
|
| 45 |
+
fallback_output = gr.Textbox(label="π‘ Suggested Fallback Clause", lines=3)
|
| 46 |
+
translation_output = gr.Textbox(label="π Portuguese Translation", lines=3)
|
| 47 |
+
|
| 48 |
+
parse_btn.click(fn=handle_input, inputs=[file_input, text_input], outputs=[contract_display, summary_output, metadata_output, risk_output, fallback_output])
|
| 49 |
+
summarize_btn.click(fn=summarize_text, inputs=[contract_display], outputs=[summary_output])
|
| 50 |
+
metadata_btn.click(fn=extract_metadata, inputs=[contract_display], outputs=[metadata_output])
|
| 51 |
+
risk_btn.click(fn=detect_risks, inputs=[contract_display], outputs=[risk_output])
|
| 52 |
+
fallback_btn.click(fn=suggest_fallback, inputs=[contract_display], outputs=[fallback_output])
|
| 53 |
+
translate_btn.click(fn=translate_text, inputs=[contract_display], outputs=[translation_output])
|
| 54 |
+
|
| 55 |
+
if __name__ == "__main__":
|
| 56 |
+
demo.launch()
|