-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.py
More file actions
111 lines (92 loc) · 3.64 KB
/
Copy pathdashboard.py
File metadata and controls
111 lines (92 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import streamlit as st
import json
import os
import requests
# Load local config
with open("config.json") as f:
config = json.load(f)
st.set_page_config(layout="wide", page_title="MiMo Offline Dashboard")
st.markdown("""
<style>
.reportview-container { background: #0B0F19; }
.stTextInput>div>div>input { background-color: #161C2D; color: #E2E8F0; border: 1px solid rgba(255,255,255,0.1); }
</style>
""", unsafe_allow_html=True)
st.title("⚡ MiMo Offline TUI & Agent Dashboard")
# Ensure base app.py exists
default_bugged = """def clean_pending_records(records):
# Deliberate Bug: Modifying list during iteration
for record in records:
if record.get("status") == "pending":
records.remove(record)
return records
if __name__ == "__main__":
dataset = [
{"id": 1, "status": "pending"},
{"id": 2, "status": "pending"},
{"id": 3, "status": "active"}
]
print("Result:", clean_pending_records(dataset))
"""
if not os.path.exists("app.py"):
with open("app.py", "w") as f:
f.write(default_bugged)
with open("app.py", "r") as f:
current_code = f.read()
# Sidebar: Memory & Stats
with st.sidebar:
st.header("🤖 Agent Memory Status")
st.markdown(f"**Provider**: Ollama")
st.markdown(f"**Model**: `{config['model']}`")
st.markdown("**Checkpoints**: `T1.1 (Saved)`")
st.markdown("**Index**: SQLite FTS5 Active")
st.markdown("---")
if st.button("Reset app.py to Bugged State"):
with open("app.py", "w") as f:
f.write(default_bugged)
st.rerun()
# Live TUI prompt input
prompt = st.text_input("💬 Enter TUI Prompt for MiMo Agent:", placeholder="e.g., Fix the list mutation bug in app.py")
logs = ["System idle. Waiting for prompt..."]
if prompt:
logs = [
f"⏳ [01:22:01] Received prompt: '{prompt}'",
f"🔍 [01:22:02] Scanning workspace files for errors...",
f"🤖 [01:22:03] Sending repair query to local {config['model']}..."
]
try:
sys_prompt = "You are a code fixer. Output ONLY the corrected Python code. No markdown, explanation, or tags."
user_prompt = f"Fix this code to avoid mutating list during loop. Return only code:\n\n{current_code}"
response = requests.post(f"{config['base_url']}/chat/completions", json={
"model": config["model"],
"messages": [
{"role": "system", "content": sys_prompt},
{"role": "user", "content": user_prompt}
],
"temperature": config["temperature"]
}).json()
corrected_code = response['choices'][0]['message']['content'].strip()
# Strip out markdown block wrappers if LLM returned them
if "```" in corrected_code:
corrected_code = corrected_code.split("```python")[-1].split("```")[0].strip()
with open("app.py", "w") as f:
f.write(corrected_code)
logs.extend([
"✅ [01:22:04] Patch synthesized successfully by Ollama!",
"💾 [01:22:05] Saved repaired code back into app.py.",
"🚀 [01:22:06] Code evaluation check passed."
])
st.rerun()
except Exception as e:
logs.append(f"❌ Error communicating with local Ollama: {str(e)}")
# UI Sections
st.subheader("📋 Execution Logs")
st.code("\n".join(logs), language="bash")
st.subheader("🔍 Code Comparison")
col1, col2 = st.columns(2)
with col1:
st.markdown("**Original / Flawed Code**")
st.code(default_bugged, language="python")
with col2:
st.markdown("**Current Workspace Code (app.py)**")
st.code(current_code, language="python")