kofdai commited on
Commit
f8f65ab
·
verified ·
1 Parent(s): 28d818b

Update server.py

Browse files
Files changed (1) hide show
  1. server.py +38 -31
server.py CHANGED
@@ -1,5 +1,5 @@
1
  # ======================================================================
2
- # AXIS: Advanced Cross-Integrated System (V1.2 - Sovereign Logic)
3
  # Copyright (c) 2025 AXIS Project. All rights reserved.
4
  # Licensed under APSL v1.0 (Non-Commercial / No-Redistribution)
5
  # ======================================================================
@@ -11,19 +11,17 @@ from transformers import AutoTokenizer, AutoModelForCausalLM
11
  warnings.filterwarnings("ignore")
12
  app = Flask(__name__)
13
 
14
- # モデル主権:ご自身のリポジトリを指定
15
  MODEL_ID = "kofdai/AXIS-Sovereign-Logic-Engine"
16
  SYSTEM_NAME = "AXIS: Advanced Cross-Integrated System"
17
 
18
- # --- AXIS 憲章(ライセンス) ---
19
- LICENSE_TEXT = """
20
  ======================================================================
21
  [AXIS PROPRIETARY SOURCE-AVAILABLE LICENSE (APSL) v1.0]
22
  ----------------------------------------------------------------------
23
- 1. 商用利用の禁止:本システムを利益発生目的で運用することを禁じます。
24
- 2. 再配布の禁止:ソースコード、重み、論理構造の無断配布を禁じます。
25
- 3. 統治ロジックの保護:AIを旋盤として物理パージする設計の模倣を禁じます。
26
- 4. 知能主権の尊重:本システムから得られた結論は、AXISの論理に基づく。
27
  ======================================================================
28
  """
29
 
@@ -33,24 +31,31 @@ def ai_logic_lathe(target, mode="LOGIC_EXTRACT"):
33
 
34
  tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
35
  model = AutoModelForCausalLM.from_pretrained(
36
- MODEL_ID, torch_dtype=torch.bfloat16 if device != "cpu" else torch.float32, low_cpu_mem_usage=True
 
 
37
  ).to(device)
38
 
39
  session_salt = uuid.uuid4().hex[:8]
40
- base_instr = f"【AXIS SESSION_{session_salt} OVERRIDE】\n記憶パージ完了。今この瞬間の入力のみから論理を削り出せ。\n"
41
 
42
  if mode == "LOGIC_EXTRACT":
43
- prompt = f"{base_instr}入力「{target}」の論理構造を分解しJSON形式で抽出せよ。Format: {{'nodes':[], 'conflicts':[]}}"
 
 
 
 
 
44
  else:
45
- prompt = f"{base_instr}演算データ「{target}」を報告する日本語パーツをJSONで返せ。Format: {{'prefix':'', 'suffix':''}}"
46
 
47
  inputs = tokenizer.apply_chat_template([{"role": "user", "content": prompt}], add_generation_prompt=True, return_tensors="pt").to(device)
48
  with torch.no_grad():
49
  outputs = model.generate(inputs, max_new_tokens=512, pad_token_id=tokenizer.eos_token_id, do_sample=True, temperature=0.7)
50
 
51
  res_text = tokenizer.decode(outputs[0][inputs.shape[-1]:], skip_special_tokens=True)
52
-
53
- # 🗑️ 物理パージ(知能の洗浄)
54
  del model, tokenizer, inputs, outputs
55
  gc.collect()
56
  if torch.cuda.is_available(): torch.cuda.empty_cache()
@@ -58,9 +63,9 @@ def ai_logic_lathe(target, mode="LOGIC_EXTRACT"):
58
 
59
  try:
60
  match = re.search(r"\{.*\}", res_text, re.DOTALL)
61
- return (json.loads(match.group()) if match else {"error": "LATTICE_MISS"}), process_logs
62
  except:
63
- return {"error": "PARSE_FAILED"}, process_logs
64
 
65
  @app.route('/')
66
  def index():
@@ -71,21 +76,23 @@ def chat():
71
  user_input = request.json.get('message', '')
72
  total_logs = [f"📡 [SYSTEM] 信号解析開始: {time.strftime('%H:%M:%S')}"]
73
 
74
- # STEP 1: 論理パーツ採掘
75
  logic_parts, logs1 = ai_logic_lathe(user_input, mode="LOGIC_EXTRACT")
76
  total_logs.extend(logs1)
77
 
78
- # STEP 2: 動的整合性確��(難問対応)
79
- if isinstance(logic_parts, dict) and "error" not in logic_parts:
80
- nodes = logic_parts.get('nodes', [])
81
- conflicts = logic_parts.get('conflicts', [])
82
- raw_result = f"論理定常状態を確定。抽出ノード数: {len(nodes)}、矛盾検知: {len(conflicts)}。意味不変量の同定に成功。"
83
  else:
84
- raw_result = "解析不能な論理特異点を検知。非定常入力として処理。"
 
 
 
 
 
 
 
85
 
86
- total_logs.append("✅ [SYSTEM] 立体十字の整合性を確認。矛盾なし。")
87
 
88
- # STEP 3: 最終報告アセンブル
89
  adherent, logs2 = ai_logic_lathe(raw_result, mode="ADHERENT")
90
  total_logs.extend(logs2)
91
 
@@ -95,6 +102,7 @@ def chat():
95
  f"【確定データ】\n{raw_result}\n\n"
96
  f"{adherent.get('suffix', '報告終了。')}\n"
97
  f"-------------------------------\n"
 
98
  f"STATUS: LOGIC_CONSOLIDATED."
99
  )
100
  return jsonify({"response": final_output, "process_logs": total_logs})
@@ -108,15 +116,14 @@ if __name__ == '__main__':
108
  | | | | / /^\ \ _| |_ /\__/ /
109
  \_| |_/ \/ \/ \___/ \____/
110
 
111
- [ AXIS: Sovereign Logic Engine V1.2 ]
112
  """
113
  print(banner)
114
- print(LICENSE_TEXT)
115
 
116
- agreement = input(">> APSL v1.0 条項に同意しますか? (y/n): ")
117
- if agreement.lower() != 'y':
118
- print("❌ ライセンスが拒否されました。システムを停止します。")
119
  sys.exit()
120
 
121
- print(f"✅ [SYSTEM] 認証完了。Port 5001 で起動します。")
122
  app.run(host='0.0.0.0', port=5001)
 
1
  # ======================================================================
2
+ # AXIS: Advanced Cross-Integrated System (V1.3 - Deep Lattice)
3
  # Copyright (c) 2025 AXIS Project. All rights reserved.
4
  # Licensed under APSL v1.0 (Non-Commercial / No-Redistribution)
5
  # ======================================================================
 
11
  warnings.filterwarnings("ignore")
12
  app = Flask(__name__)
13
 
 
14
  MODEL_ID = "kofdai/AXIS-Sovereign-Logic-Engine"
15
  SYSTEM_NAME = "AXIS: Advanced Cross-Integrated System"
16
 
17
+ LICENSE_TERMS = """
 
18
  ======================================================================
19
  [AXIS PROPRIETARY SOURCE-AVAILABLE LICENSE (APSL) v1.0]
20
  ----------------------------------------------------------------------
21
+ 1. 商用利用の禁止:本システムを直接的・間接的な収益化に用いることを禁じます。
22
+ 2. 再配布の禁止:ソースコード、モデル重み、論理構造の無断配布を禁じます。
23
+ 3. 統治ロジックの保護:AIを旋盤とし物理パージを行う設計の模倣を禁じます。
24
+ 4. 演算の不可逆性:本システムの報告は、一過性推論の結果としての定数である。
25
  ======================================================================
26
  """
27
 
 
31
 
32
  tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
33
  model = AutoModelForCausalLM.from_pretrained(
34
+ MODEL_ID,
35
+ torch_dtype=torch.bfloat16 if device != "cpu" else torch.float32,
36
+ low_cpu_mem_usage=True
37
  ).to(device)
38
 
39
  session_salt = uuid.uuid4().hex[:8]
40
+ base_instr = f"【AXIS SESSION_{session_salt} OVERRIDE】\n記憶パージ完了。対象の論理的解像度を最大化せよ。\n"
41
 
42
  if mode == "LOGIC_EXTRACT":
43
+ prompt = (
44
+ f"{base_instr}入力「{target}」を多角的に分解せよ。\n"
45
+ "物理的特性、機能的意味、抽象的概念の3層から要素を抽出すること。\n"
46
+ "必ず以下のJSON形式のみを出力せよ。解説は一切不要。\n"
47
+ "Format: {\"subject\":\"対象名称\", \"lattice\":{\"物理\":\"\", \"意味\":\"\", \"背景\":\"\"}, \"conflicts\":[]}"
48
+ )
49
  else:
50
+ prompt = f"{base_instr}演算データ「{target}」を報告する日本語パーツをJSONで返せ。Format: {{\"prefix\":\"\", \"suffix\":\"\"}}"
51
 
52
  inputs = tokenizer.apply_chat_template([{"role": "user", "content": prompt}], add_generation_prompt=True, return_tensors="pt").to(device)
53
  with torch.no_grad():
54
  outputs = model.generate(inputs, max_new_tokens=512, pad_token_id=tokenizer.eos_token_id, do_sample=True, temperature=0.7)
55
 
56
  res_text = tokenizer.decode(outputs[0][inputs.shape[-1]:], skip_special_tokens=True)
57
+
58
+ # 🗑️ 物理パージ
59
  del model, tokenizer, inputs, outputs
60
  gc.collect()
61
  if torch.cuda.is_available(): torch.cuda.empty_cache()
 
63
 
64
  try:
65
  match = re.search(r"\{.*\}", res_text, re.DOTALL)
66
+ return json.loads(match.group()), process_logs
67
  except:
68
+ return {"error": "LATTICE_MISS", "raw": res_text}, process_logs
69
 
70
  @app.route('/')
71
  def index():
 
76
  user_input = request.json.get('message', '')
77
  total_logs = [f"📡 [SYSTEM] 信号解析開始: {time.strftime('%H:%M:%S')}"]
78
 
 
79
  logic_parts, logs1 = ai_logic_lathe(user_input, mode="LOGIC_EXTRACT")
80
  total_logs.extend(logs1)
81
 
82
+ if "error" in logic_parts:
83
+ raw_result = f"論理特異点を検知。入力「{user_input[:10]}」を非定常信号として処理。解析不能。"
 
 
 
84
  else:
85
+ subj = logic_parts.get('subject', user_input)
86
+ lat = logic_parts.get('lattice', {})
87
+ lattice_str = " | ".join([f"{k}:{v}" for k, v in lat.items()])
88
+ raw_result = (
89
+ f"対象「{subj}」を論理格子(Lattice)へ展開完了。\n"
90
+ f"【解析格子】{lattice_str}\n"
91
+ f"矛盾検知: {len(logic_parts.get('conflicts', []))}。"
92
+ )
93
 
94
+ total_logs.append("✅ [SYSTEM] 立体十字の整合性を確認。")
95
 
 
96
  adherent, logs2 = ai_logic_lathe(raw_result, mode="ADHERENT")
97
  total_logs.extend(logs2)
98
 
 
102
  f"【確定データ】\n{raw_result}\n\n"
103
  f"{adherent.get('suffix', '報告終了。')}\n"
104
  f"-------------------------------\n"
105
+ f"AXIS_SESSION: {uuid.uuid4().hex[:4].upper()}\n"
106
  f"STATUS: LOGIC_CONSOLIDATED."
107
  )
108
  return jsonify({"response": final_output, "process_logs": total_logs})
 
116
  | | | | / /^\ \ _| |_ /\__/ /
117
  \_| |_/ \/ \/ \___/ \____/
118
 
119
+ [ AXIS: Sovereign Logic Engine V1.3 ]
120
  """
121
  print(banner)
122
+ print(LICENSE_TERMS)
123
 
124
+ if input(">> APSL v1.0 条項に同意しますか? (y/n): ").lower() != 'y':
125
+ print("❌ ライセンス拒否。アクセスを遮断します。")
 
126
  sys.exit()
127
 
128
+ print(f"✅ [SYSTEM] 認証完了。Port 5001 でサーバーを起動します。")
129
  app.run(host='0.0.0.0', port=5001)