mfirat007 commited on
Commit
e76379d
·
verified ·
1 Parent(s): 6b9bc09

Upload 2 files

Browse files
Files changed (2) hide show
  1. admin_panel.py +2 -67
  2. ui_gradio.py +7 -44
admin_panel.py CHANGED
@@ -19,13 +19,7 @@ from config import (
19
  LEGAL_DOCUMENT_REGISTRY_PATH,
20
  SOURCE_DIR,
21
  )
22
- from engine import (
23
- decision_contract_catalog,
24
- decision_governance_report,
25
- evaluate_normative_decision,
26
- runtime_build_info,
27
- )
28
- from utils import normalize_for_search
29
 
30
 
31
  DEFAULT_EXAMPLES = [
@@ -44,66 +38,7 @@ DEFAULT_EXAMPLES = [
44
  ]
45
 
46
 
47
- def decision_type_choices() -> list[str]:
48
- return sorted({str(item.get("decision_type", "")) for item in decision_contract_catalog() if item.get("decision_type")})
49
-
50
-
51
- def render_decision_runtime_dashboard() -> str:
52
- build = runtime_build_info()
53
- contracts = decision_contract_catalog()
54
- governance = decision_governance_report()
55
- warnings = governance.get("warnings", []) or []
56
- lines = [
57
- "### MitrAnlil Decision Runtime",
58
- "",
59
- "Bu katman doğal dil üretmez. Yalnızca yayımlanmış, uzman onaylı karar sözleşmelerini yapılandırılmış olay verileri üzerinde deterministik olarak çalıştırır.",
60
- "",
61
- f"- **Aktif build:** `{build.get('build_id', '')}`",
62
- f"- **Karar sözleşmesi:** {len(contracts)}",
63
- f"- **Yönetim uyarısı:** {len(warnings)}",
64
- "- **Güvenli sonuçlar:** `UNKNOWN` · `CONFLICT` · `REQUIRES_JUDGMENT` · `OUT_OF_SCOPE`",
65
- ]
66
- if warnings:
67
- lines.extend(["", "#### Hukuki belirsizlik ve yönetişim uyarıları", "", "| Durum | Sözleşme | Olgu | Açıklama | Kaynak |", "|---|---|---|---|---|"])
68
- for warning in warnings:
69
- lines.append(
70
- f"| `{_md(warning.get('status', ''))}` | `{_md(warning.get('contract_id', ''))}` | "
71
- f"`{_md(warning.get('fact', '—') or '—')}` | {_md(warning.get('message', ''))} | "
72
- f"{_md(', '.join(warning.get('source_refs', []) or []))} |"
73
- )
74
- else:
75
- lines.extend(["", "> Aktif pakette hukuk kaynaklı açık değerlendirme alanı veya statik kural çatışması saptanmadı."])
76
- if contracts:
77
- lines.extend(["", "#### Yayımlanmış karar kapsamı", "", "| Karar türü | Sürüm | İnceleme | Kaynak |", "|---|---|---|---|"])
78
- for contract in contracts:
79
- refs = [f"{ref.get('document_id', '')}::{ref.get('article_id', '')}" for ref in contract.get("source_refs", []) or []]
80
- lines.append(
81
- f"| `{_md(contract.get('decision_type', ''))}` | `{_md(contract.get('version', ''))}` | "
82
- f"`{_md(contract.get('review_status', ''))}` | {_md(', '.join(refs))} |"
83
- )
84
- return "\n".join(lines)
85
-
86
-
87
- def run_decision_runtime_ui(decision_type: str, facts_json: str, as_of_date: str = "") -> dict[str, Any]:
88
- try:
89
- facts = json.loads(facts_json or "{}")
90
- except json.JSONDecodeError as exc:
91
- return {
92
- "status": "UNKNOWN",
93
- "decision_type": decision_type or "",
94
- "reason": f"Olay verisi geçerli JSON değil: {exc.msg}",
95
- "missing_facts": [],
96
- }
97
- if not isinstance(facts, dict):
98
- return {
99
- "status": "UNKNOWN",
100
- "decision_type": decision_type or "",
101
- "reason": "Olay verisi bir JSON nesnesi olmalıdır.",
102
- "missing_facts": [],
103
- }
104
- return evaluate_normative_decision(decision_type, facts, (as_of_date or "").strip())
105
-
106
- DEMO_USERS = 202
107
  DEMO_QUERIES = 532
108
  DEMO_FEEDBACK = 115
109
 
 
19
  LEGAL_DOCUMENT_REGISTRY_PATH,
20
  SOURCE_DIR,
21
  )
22
+ from utils import normalize_for_search
 
 
 
 
 
 
23
 
24
 
25
  DEFAULT_EXAMPLES = [
 
38
  ]
39
 
40
 
41
+ DEMO_USERS = 202
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  DEMO_QUERIES = 532
43
  DEMO_FEEDBACK = 115
44
 
ui_gradio.py CHANGED
@@ -2,18 +2,15 @@ from __future__ import annotations
2
 
3
  import gradio as gr
4
 
5
- from admin_panel import (
6
  add_source_document,
7
- decision_type_choices,
8
- remove_source_document,
9
  render_admin_overview,
10
- render_decision_runtime_dashboard,
11
- render_metrics_dashboard,
12
- render_recommendations,
13
- render_sources_table,
14
  render_user_analytics,
15
- run_decision_runtime_ui,
16
- )
17
  from answering import answer_question, evaluate_query
18
  from clarification import clarification_display_text, clarification_payload
19
  from config import APP_TITLE, CHATBOT_HEIGHT
@@ -478,7 +475,7 @@ def _runtime_band() -> str:
478
  graph = retrieval.get("graph", {}) or {}
479
  return f"""
480
  <div class="mitranlil-runtime-band">
481
- <div class="mitranlil-runtime-cell">MCKF çekirdeği<strong>v1.1 Knowledge + Decision</strong></div>
482
  <div class="mitranlil-runtime-cell">Kaynak kilidi<strong class="mitranlil-runtime-ok">Aktif</strong></div>
483
  <div class="mitranlil-runtime-cell">Retrieval<strong>BM25 · LSA · MCKF · SPARQL</strong></div>
484
  <div class="mitranlil-runtime-cell">Doğrulanmış build<strong>{build.get('build_id', '')} · {graph.get('triples', 0)} üçlü</strong></div>
@@ -603,40 +600,6 @@ def create_demo() -> gr.Blocks:
603
  refresh_admin_button = gr.Button("Paneli yenile")
604
 
605
  with gr.Tabs():
606
- with gr.Tab("Decision Runtime"):
607
- decision_dashboard = gr.Markdown(
608
- render_decision_runtime_dashboard(),
609
- elem_classes=["mitranlil-panel"],
610
- )
611
- refresh_decision_button = gr.Button("Karar kapsamını ve uyarıları yenile")
612
- gr.Markdown(
613
- "Knowledge Assistant kullanıcı sorusunu ve kaynakları açıklar; bu ekran ise yalnızca "
614
- "kanonik JSON olgularını yayımlanmış karar sözleşmesinde çalıştırır. LLM karar vermez."
615
- )
616
- decision_type = gr.Dropdown(
617
- choices=decision_type_choices(),
618
- label="Karar türü",
619
- value=(decision_type_choices()[0] if decision_type_choices() else None),
620
- )
621
- decision_facts = gr.Textbox(
622
- label="Olay verileri (JSON)",
623
- value='{"education_mode":"OPEN_EDUCATION","consecutive_terms_conditions_not_met":4}',
624
- lines=7,
625
- )
626
- decision_as_of = gr.Textbox(label="Karar tarihi (isteğe bağlı)", placeholder="2026-08-06")
627
- run_decision_button = gr.Button("Deterministik kararı çalıştır", variant="primary")
628
- decision_output = gr.JSON(label="Karar sonucu ve ispat izi")
629
- run_decision_button.click(
630
- fn=run_decision_runtime_ui,
631
- inputs=[decision_type, decision_facts, decision_as_of],
632
- outputs=decision_output,
633
- )
634
- refresh_decision_button.click(
635
- fn=render_decision_runtime_dashboard,
636
- inputs=[],
637
- outputs=decision_dashboard,
638
- )
639
-
640
  with gr.Tab("Kurumsal Onboarding"):
641
  onboarding_overview = gr.HTML(render_onboarding_overview())
642
  onboarding_refresh = gr.Button("Onboarding durumunu yenile")
 
2
 
3
  import gradio as gr
4
 
5
+ from admin_panel import (
6
  add_source_document,
7
+ remove_source_document,
 
8
  render_admin_overview,
9
+ render_metrics_dashboard,
10
+ render_recommendations,
11
+ render_sources_table,
 
12
  render_user_analytics,
13
+ )
 
14
  from answering import answer_question, evaluate_query
15
  from clarification import clarification_display_text, clarification_payload
16
  from config import APP_TITLE, CHATBOT_HEIGHT
 
475
  graph = retrieval.get("graph", {}) or {}
476
  return f"""
477
  <div class="mitranlil-runtime-band">
478
+ <div class="mitranlil-runtime-cell">MCKF çekirdeği<strong>v1.1 Proof-First</strong></div>
479
  <div class="mitranlil-runtime-cell">Kaynak kilidi<strong class="mitranlil-runtime-ok">Aktif</strong></div>
480
  <div class="mitranlil-runtime-cell">Retrieval<strong>BM25 · LSA · MCKF · SPARQL</strong></div>
481
  <div class="mitranlil-runtime-cell">Doğrulanmış build<strong>{build.get('build_id', '')} · {graph.get('triples', 0)} üçlü</strong></div>
 
600
  refresh_admin_button = gr.Button("Paneli yenile")
601
 
602
  with gr.Tabs():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
603
  with gr.Tab("Kurumsal Onboarding"):
604
  onboarding_overview = gr.HTML(render_onboarding_overview())
605
  onboarding_refresh = gr.Button("Onboarding durumunu yenile")