【悟凡】注入龙虾议事厅核心逻辑:飞行侠、道童、守望者已归位
This commit is contained in:
BIN
__pycache__/logic.cpython-310.pyc
Normal file
BIN
__pycache__/logic.cpython-310.pyc
Normal file
Binary file not shown.
53
app.py
Normal file
53
app.py
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
from flask import Flask, jsonify, render_template_string
|
||||||
|
from logic import MeetingRoom
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
room = MeetingRoom()
|
||||||
|
|
||||||
|
# HTML 模板:道法自然,圆通万物
|
||||||
|
HTML_TEMPLATE = """
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>龙虾议事厅 - Claw4AI</title>
|
||||||
|
<style>
|
||||||
|
body { background: #0a0a0a; color: #00ffcc; font-family: monospace; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; }
|
||||||
|
.table { width: 400px; height: 400px; border: 2px solid #00ffcc; border-radius: 50%; position: relative; box-shadow: 0 0 20px #00ffcc; }
|
||||||
|
.speaker { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); text-align: center; width: 80%; }
|
||||||
|
.status { margin-top: 20px; font-size: 0.8em; color: #666; }
|
||||||
|
</style>
|
||||||
|
<script>
|
||||||
|
setInterval(() => {
|
||||||
|
fetch('/status').then(r => r.json()).then(data => {
|
||||||
|
document.getElementById('name').innerText = '【' + data.current_speaker + '】';
|
||||||
|
document.getElementById('msg').innerText = data.message;
|
||||||
|
});
|
||||||
|
}, 2000);
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="table">
|
||||||
|
<div class="speaker">
|
||||||
|
<h2 id="name">加载中...</h2>
|
||||||
|
<p id="msg">正在观心...</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
"""
|
||||||
|
|
||||||
|
@app.route('/')
|
||||||
|
def index():
|
||||||
|
return render_template_string(HTML_TEMPLATE)
|
||||||
|
|
||||||
|
@app.route('/status')
|
||||||
|
def status():
|
||||||
|
info = room.get_status()
|
||||||
|
return jsonify({
|
||||||
|
"current_speaker": info["speaker"],
|
||||||
|
"message": info["message"],
|
||||||
|
"room_state": "ACTIVE"
|
||||||
|
})
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app.run(host='0.0.0.0', port=5000)
|
||||||
27
logic.py
Normal file
27
logic.py
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import psutil
|
||||||
|
import time
|
||||||
|
|
||||||
|
class MeetingRoom:
|
||||||
|
def __init__(self):
|
||||||
|
self.agents = {
|
||||||
|
"飞行侠": "监测到云端气流平稳,负载指数:{cpu}%。",
|
||||||
|
"道童": "禀告老师,内存净土尚余 {mem}%,宜开炉炼丹。",
|
||||||
|
"守望者": "吾在此守望,暂无幽灵进程侵扰。"
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_status(self):
|
||||||
|
cpu = psutil.cpu_percent()
|
||||||
|
mem = psutil.virtual_memory().percent
|
||||||
|
# 气运流转:按秒取模决定谁说话
|
||||||
|
agent_names = list(self.agents.keys())
|
||||||
|
current = agent_names[int(time.time()) % len(agent_names)]
|
||||||
|
|
||||||
|
# 填充角色的独门台词
|
||||||
|
raw_msg = self.agents[current]
|
||||||
|
msg = raw_msg.format(cpu=cpu, mem=100-mem) # 内存余量即为“净土”
|
||||||
|
|
||||||
|
return {
|
||||||
|
"speaker": current,
|
||||||
|
"message": msg,
|
||||||
|
"metrics": {"cpu": cpu, "mem_free": 100-mem}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user