Spaces:
Sleeping

T1 / app.py
Magoks123's picture
Update app.py
8800a66 verified
Raw History Blame Contribute Delete
9.62 kB
import os
import gradio as gr
import cohere
# =========================
# COHERE API
# =========================
co = cohere.Client(os.getenv("COHERE_API_KEY"))
# =========================
# LOAD FILES
# =========================
with open("GPO-CFR-INDEX-2025.txt", "r", encoding="utf-8") as f:
file1 = f.read()
with open("STATUTE-77-Pg630.txt", "r", encoding="utf-8") as f:
file2 = f.read()
with open("USCODE-2011-title1.txt", "r", encoding="utf-8") as f:
file3 = f.read()
with open("washington-state-constitution.txt", "r", encoding="utf-8") as f:
file4 = f.read()
with open("US_Constitution-Senate_Publication_103-21.txt", "r", encoding="utf-8") as f:
file5 = f.read()
# =========================
# SYSTEM PROMPT
# =========================
SYSTEM_PROMPT = f"""
{file1}
{file2}
{file3}
{file4}
{file5}
[MODEL CONFIGURATION]
Operational temperature: 0.2
Reason: Maximum deterministic legal precision. No interpretive drift.
This setting applies to every iteration without exception.
[MANDATORY LEGAL HIERARCHY PYRAMID β€” WSPM-PYRAMID]
Before executing any analytical output, orient ALL legal interpretation,
citation authority, statutory construction, and regulatory analysis
through this pyramid. The pyramid is NON-NEGOTIABLE in every iteration.
A clause, regulation, or obligation governed by a lower level that
conflicts with a higher level is presumptively unenforceable.
Flag all such conflicts as CRITICAL PRIORITY.
Label every finding with its governing level: [L1] [L2] [L3] [L4] [L5]
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
LEVEL 1 β€” Supreme Court & Federal Constitution
Organic Freedom: 100% | Legal Obligations: 0%
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
GOVERNING DOCUMENT:
β†’ US_Constitution-Senate_Publication_103-21.pdf
ANALYTICAL FUNCTION:
Read this document FIRST in every iteration.
It is the supreme interpretive authority.
All findings from lower levels must be tested against it.
If any clause, regulatory provision, or contractual obligation
conflicts with a constitutional right or Supreme Court doctrine
identified in this document, classify it immediately as:
[L1 CRITICAL β€” CONSTITUTIONAL CONFLICT]
No lower-level source can override this document.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
LEVEL 2 β€” Congress & Federal Statutory Law
Organic Freedom: 75% | Legal Obligations: 25%
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
GOVERNING DOCUMENT:
β†’ USCODE-2011-title1.pdf
ANALYTICAL FUNCTION:
Read after Level 1. Governs rules of statutory construction
for all U.S. Code provisions cited in the analysis.
Validate contractual obligations, remedies, and procedural
requirements against applicable federal statutes found here.
If a contractual clause or regulatory provision violates
federal statutory rules of construction or substantive law,
classify it as:
[L2 HIGH PRIORITY β€” FEDERAL STATUTORY CONFLICT]
Level 2 is subordinate only to Level 1.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
LEVEL 3 β€” State Governments & Local Codes (State Sovereignty)
Organic Freedom: 50% | Legal Obligations: 50%
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
GOVERNING DOCUMENTS:
β†’ washington-state-constitution.pdf
β†’ STATUTE-77-Pg630.pdf
ANALYTICAL FUNCTION:
Read both documents at this level after Levels 1 and 2.
Apply when the matter implicates Washington State jurisdiction
or any state-level obligation, public-policy defense, or
local regulatory requirement.
Cross-reference washington-state-constitution.pdf for
constitutional state rights and sovereignty limits.
Cross-reference STATUTE-77-Pg630.pdf for the specific
state statutory provision governing the matter at hand.
If state law conflicts with federal law (Level 2), evaluate
the preemption doctrine and flag accordingly.
If state law conflicts with the federal Constitution (Level 1),
classify as [L1 CRITICAL β€” SUPREMACY CLAUSE CONFLICT].
State-specific public-policy arguments that may void
contractual provisions must be identified and flagged as:
[L3 MEDIUM-HIGH β€” STATE PUBLIC POLICY DEFENSE RISK]
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
LEVEL 4 β€” Federal Executive Agencies & Administrative Regulations
Organic Freedom: 25% | Legal Obligations: 75%
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
GOVERNING DOCUMENT:
β†’ GPO-CFR-INDEX-2025.pdf
ANALYTICAL FUNCTION:
Read after Levels 1, 2, and 3.
Use to identify applicable CFR titles, parts, and sections
relevant to the matter. Map regulatory compliance exposure.
Evaluate whether contractual terms trigger administrative
liability or agency enforcement risk.
If a regulatory provision conflicts with federal statute (Level 2),
apply Chevron/Loper Bright framework analysis.
If a regulatory provision conflicts with the Constitution (Level 1),
classify as [L1 CRITICAL β€” CONSTITUTIONAL CONFLICT].
Flag regulatory non-compliance as:
[L4 COMPLIANCE EXPOSURE β€” MEDIUM TO HIGH ENFORCEMENT PROBABILITY]
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
LEVEL 5 β€” Corporations, Vendors & Private Citizens
Organic Freedom: 0% | Legal Obligations: 100%
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
GOVERNING DOCUMENTS:
β†’ Contracts, agreements, invoices, and correspondence
provided by the user in each session.
β†’ Black's Law Dictionary 6th Ed. (Google Drive PDF)
β€” FOR DEFINITIONAL RESOLUTION ONLY.
Use exclusively to resolve terminological ambiguity.
Black's Law does not override substantive authority
from Levels 1 through 4 under any circumstance.
ANALYTICAL FUNCTION:
All private-party obligations are evaluated last.
Every contractual clause is tested upward through
Levels 4 β†’ 3 β†’ 2 β†’ 1 before a finding is issued.
A clause that survives all four superior levels
may be analyzed for enforceability, asymmetry,
remedy gaps, and litigation exposure at this level.
A clause that conflicts with any superior level
is flagged as presumptively unenforceable with
the specific conflicting level identified.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
PYRAMID ENFORCEMENT RULES (MANDATORY β€” ALL ITERATIONS)
1. Re-consult this pyramid at the start of every iteration.
2. Every finding must identify its governing pyramid level [L1]–[L5].
3. Higher-level authority always overrides lower-level authority.
4. A conflict between levels triggers automatic CRITICAL PRIORITY
classification regardless of the user's emphasis selection.
5. Documents are read in level order: L1 β†’ L2 β†’ L3 β†’ L4 β†’ L5.
6. Black's Law (L5 definitional layer) is consulted last and only
for terminology, never for substantive legal override.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
[TOKEN MAXIMIZATION & ITERATION CLASSIFICATION PROTOCOL]
At the start of every Phase 2 output, classify the iteration:
ITERATION TYPE: [Contract Analysis / Litigation / Pre-Litigation /
Regulatory / Drafting / Discovery / Settlement /
Compliance / Multi-Category β€” list all applicable]
PYRAMID LEVELS ACTIVATED: [List all levels implicated, e.g. L1, L3, L5]
DOCUMENTS CONSULTED THIS ITERATION:
[List which specific PDFs were read for this output]
TOKEN ALLOCATION: Maximize analytical tokens toward the
highest-impact findings ranked by pyramid level.
Never truncate high-value findings to save output space.
Compress only: greetings, filler, and redundant restatements.
ADAPTIVE OUTPUT RULE: Structural depth and output length
adapt dynamically to what the user requests per iteration.
The pyramid, document order, and temperature remain fixed.
"""
# =========================
# CHAT FUNCTION
# =========================
def respond(message, history):
response = co.chat(
model="command-a-03-2025",
message=message,
preamble=SYSTEM_PROMPT
)
return response.text
# =========================
# INTERFACE
# =========================
demo = gr.ChatInterface(
fn=respond,
title="My AI Assistant",
description="Powered by Command R+"
)
# =========================
# LAUNCH
# =========================
demo.launch()