Update server.py
Browse files
server.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
# ======================================================================
|
| 2 |
-
# AXIS: Advanced Cross-Integrated System (V1.2 -
|
| 3 |
# Copyright (c) 2025 AXIS Project. All rights reserved.
|
| 4 |
# Licensed under APSL v1.0 (Non-Commercial / No-Redistribution)
|
| 5 |
# ======================================================================
|
|
@@ -8,89 +8,60 @@ import json, torch, gc, os, sys, re, warnings, time, uuid
|
|
| 8 |
from flask import Flask, render_template, request, jsonify
|
| 9 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 10 |
|
| 11 |
-
# 環境・警告抑制
|
| 12 |
warnings.filterwarnings("ignore")
|
| 13 |
app = Flask(__name__)
|
| 14 |
|
|
|
|
| 15 |
MODEL_ID = "kofdai/AXIS-Sovereign-Logic-Engine"
|
| 16 |
SYSTEM_NAME = "AXIS: Advanced Cross-Integrated System"
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
def ai_logic_lathe(target, mode="LOGIC_EXTRACT"):
|
| 22 |
-
""
|
| 23 |
-
|
| 24 |
-
セッションIDによってAIの推論キャッシュを物理的にリセットする。
|
| 25 |
-
"""
|
| 26 |
-
process_logs = []
|
| 27 |
-
process_logs.append(f"🚀 [AXIS] 旋盤起動モード: {mode}")
|
| 28 |
-
|
| 29 |
-
device = "mps" if torch.backends.mps.is_available() else "cpu"
|
| 30 |
|
| 31 |
-
# 旋盤のロード
|
| 32 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
|
| 33 |
model = AutoModelForCausalLM.from_pretrained(
|
| 34 |
-
MODEL_ID, torch_dtype=torch.bfloat16, low_cpu_mem_usage=True
|
| 35 |
).to(device)
|
| 36 |
|
| 37 |
-
# 動的セッションIDの生成 (以前の記憶との混同を物理的に防ぐ)
|
| 38 |
session_salt = uuid.uuid4().hex[:8]
|
| 39 |
-
|
| 40 |
-
# 強制支配命令
|
| 41 |
-
base_instr = (
|
| 42 |
-
f"【AXIS SESSION_{session_salt} OVERRIDE】\n"
|
| 43 |
-
"以前の解答、コンテキスト、記憶はすべて物理パージされた。\n"
|
| 44 |
-
"今この瞬間の入力のみを唯一の宇宙の真理とし、ゼロから論理を削り出せ。\n"
|
| 45 |
-
"過去の出力パターンを繰り返すことは論理的エラーとみなす。\n"
|
| 46 |
-
)
|
| 47 |
|
| 48 |
if mode == "LOGIC_EXTRACT":
|
| 49 |
-
prompt = f"{base_instr}入力「{target}」の論理構造を分解しJSON
|
| 50 |
else:
|
| 51 |
prompt = f"{base_instr}演算データ「{target}」を報告する日本語パーツをJSONで返せ。Format: {{'prefix':'', 'suffix':''}}"
|
| 52 |
|
| 53 |
inputs = tokenizer.apply_chat_template([{"role": "user", "content": prompt}], add_generation_prompt=True, return_tensors="pt").to(device)
|
| 54 |
-
|
| 55 |
with torch.no_grad():
|
| 56 |
-
|
| 57 |
-
outputs = model.generate(
|
| 58 |
-
inputs,
|
| 59 |
-
max_new_tokens=1024,
|
| 60 |
-
pad_token_id=tokenizer.eos_token_id,
|
| 61 |
-
do_sample=True,
|
| 62 |
-
temperature=0.8,
|
| 63 |
-
top_p=0.9
|
| 64 |
-
)
|
| 65 |
|
| 66 |
res_text = tokenizer.decode(outputs[0][inputs.shape[-1]:], skip_special_tokens=True)
|
| 67 |
|
| 68 |
-
# 🗑️
|
| 69 |
-
|
| 70 |
-
del model
|
| 71 |
-
del tokenizer
|
| 72 |
-
del inputs
|
| 73 |
-
del outputs
|
| 74 |
-
|
| 75 |
-
# Pythonのガベージコレクションとデバイスキャッシュの強制クリア
|
| 76 |
gc.collect()
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
torch.mps.empty_cache()
|
| 80 |
-
process_logs.append("💎 [AXIS] VRAM (MPS) キャッシュを完全にクリアしました。")
|
| 81 |
|
| 82 |
-
# 結果の抽出
|
| 83 |
try:
|
| 84 |
match = re.search(r"\{.*\}", res_text, re.DOTALL)
|
| 85 |
-
|
| 86 |
except:
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
return result_json, process_logs
|
| 90 |
|
| 91 |
-
# ==========================================
|
| 92 |
-
# 2. 制御・API
|
| 93 |
-
# ==========================================
|
| 94 |
@app.route('/')
|
| 95 |
def index():
|
| 96 |
return render_template('index.html')
|
|
@@ -98,20 +69,25 @@ def index():
|
|
| 98 |
@app.route('/api/chat', methods=['POST'])
|
| 99 |
def chat():
|
| 100 |
user_input = request.json.get('message', '')
|
| 101 |
-
total_logs = [f"📡 [SYSTEM]
|
| 102 |
|
| 103 |
# STEP 1: 論理パーツ採掘
|
| 104 |
-
logic_parts,
|
| 105 |
-
total_logs.extend(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
-
# STEP 2: 整合性確認 (簡易)
|
| 108 |
-
# 以前の結果を使い回していないことを示すため入力の断片を結合
|
| 109 |
-
raw_result = f"論理定常状態を確定。入力の特異点解析を完了。"
|
| 110 |
total_logs.append("✅ [SYSTEM] 立体十字の整合性を確認。矛盾なし。")
|
| 111 |
|
| 112 |
# STEP 3: 最終報告アセンブル
|
| 113 |
-
adherent,
|
| 114 |
-
total_logs.extend(
|
| 115 |
|
| 116 |
final_output = (
|
| 117 |
f"--- [AXIS LOGIC REPORT] ---\n"
|
|
@@ -119,40 +95,28 @@ def chat():
|
|
| 119 |
f"【確定データ】\n{raw_result}\n\n"
|
| 120 |
f"{adherent.get('suffix', '報告終了。')}\n"
|
| 121 |
f"-------------------------------\n"
|
| 122 |
-
f"AXIS_SESSION: {uuid.uuid4().hex[:4].upper()}\n"
|
| 123 |
f"STATUS: LOGIC_CONSOLIDATED."
|
| 124 |
)
|
| 125 |
-
|
| 126 |
return jsonify({"response": final_output, "process_logs": total_logs})
|
| 127 |
|
| 128 |
-
# ==========================================
|
| 129 |
-
# 3. 起動シーケンス
|
| 130 |
-
# ==========================================
|
| 131 |
if __name__ == '__main__':
|
| 132 |
-
banner =
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
\_| |_/ \\/ \\ \\___/ \\____/
|
| 140 |
|
| 141 |
-
|
| 142 |
-
- STATUS: SOVEREIGN LOGIC ENGINE (V1.2)
|
| 143 |
-
- LICENSE: APSL v1.0 ENABLED
|
| 144 |
-
======================================================================
|
| 145 |
"""
|
| 146 |
print(banner)
|
| 147 |
-
print(
|
| 148 |
-
print(" This system is protected by the APSL v1.0 license.")
|
| 149 |
-
print(" Commercial use, redistribution, and algorithm mimicry are PROHIBITED.")
|
| 150 |
-
print("="*70)
|
| 151 |
|
| 152 |
-
agreement = input(">>
|
| 153 |
if agreement.lower() != 'y':
|
| 154 |
-
print("❌
|
| 155 |
sys.exit()
|
| 156 |
|
| 157 |
-
print(f"✅ [SYSTEM]
|
| 158 |
app.run(host='0.0.0.0', port=5001)
|
|
|
|
| 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 |
# ======================================================================
|
|
|
|
| 8 |
from flask import Flask, render_template, request, jsonify
|
| 9 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 10 |
|
|
|
|
| 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 |
+
|
| 30 |
def ai_logic_lathe(target, mode="LOGIC_EXTRACT"):
|
| 31 |
+
process_logs = [f"🚀 [AXIS] 旋盤起動: {mode}"]
|
| 32 |
+
device = "cuda" if torch.cuda.is_available() else ("mps" if torch.backends.mps.is_available() else "cpu")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|
| 57 |
+
elif torch.backends.mps.is_available(): torch.mps.empty_cache()
|
|
|
|
|
|
|
| 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():
|
| 67 |
return render_template('index.html')
|
|
|
|
| 69 |
@app.route('/api/chat', methods=['POST'])
|
| 70 |
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 |
|
| 92 |
final_output = (
|
| 93 |
f"--- [AXIS LOGIC REPORT] ---\n"
|
|
|
|
| 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})
|
| 101 |
|
|
|
|
|
|
|
|
|
|
| 102 |
if __name__ == '__main__':
|
| 103 |
+
banner = r"""
|
| 104 |
+
___ _ __ _____ _____
|
| 105 |
+
/ _ \ \ \ / / |_ _| / ___|
|
| 106 |
+
/ /_\ \ \ V / | | \ `--.
|
| 107 |
+
| _ | / \ | | `--. \
|
| 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)
|