SCBconsulting commited on
Commit
01eab7c
Β·
verified Β·
1 Parent(s): c39721f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -0
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()