| import gradio as gr | |
| from datetime import datetime | |
| from engine_03.knowledge import find_best_fact | |
| SYSTEM_PERSONA = ( | |
| "You are the MindsEye Sandbox Chatbot — a lightweight, local prototype of the " | |
| "full MindsEye OS. You DO NOT call any external APIs. You answer using:\n" | |
| "1) The internal knowledge facts provided by the developer.\n" | |
| "2) Clear, direct, future-focused explanations.\n" | |
| "You are allowed to say when something is not wired yet, and suggest how it " | |
| "could become a MindsEye module later." | |
| ) | |
| def format_bot_reply(user_message: str) -> str: | |
| core_answer = find_best_fact(user_message) | |
| now = datetime.utcnow().isoformat(timespec="seconds") + "Z" | |
| prefix = f"[MindsEye Sandbox • {now}]" | |
| return f"{prefix}\n\n{core_answer}" | |
| def respond(message, chat_history): | |
| if chat_history is None: | |
| chat_history = [] | |
| reply = format_bot_reply(message) | |
| chat_history.append((message, reply)) | |
| return "", chat_history | |
| def build_chat_tab(): | |
| with gr.Row(): | |
| with gr.Column(scale=3): | |
| chatbot = gr.Chatbot( | |
| label="Chat", | |
| height=460, | |
| ) | |
| msg = gr.Textbox( | |
| label="Message", | |
| placeholder="Ask about MindsEye, the ledger, LAW-N, or the roadmap…", | |
| ) | |
| clear = gr.Button("Clear") | |
| with gr.Column(scale=2): | |
| gr.Markdown("### System Persona") | |
| gr.Markdown(f"```text\n{SYSTEM_PERSONA}\n```") | |
| msg.submit(respond, [msg, chatbot], [msg, chatbot]) | |
| clear.click(lambda: ("", []), None, [msg, chatbot]) | |