GameAI / ui_html.py
j-js's picture
Update ui_html.py
5b9d653 verified
HOME_HTML = """
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>GameAI</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 900px;
margin: 40px auto;
padding: 0 16px;
line-height: 1.5;
}
textarea {
width: 100%;
min-height: 220px;
font-family: monospace;
font-size: 14px;
padding: 12px;
box-sizing: border-box;
margin-top: 12px;
}
button {
margin-top: 12px;
padding: 10px 16px;
font-size: 14px;
cursor: pointer;
}
pre {
background: #f6f6f6;
padding: 12px;
border-radius: 8px;
white-space: pre-wrap;
word-wrap: break-word;
margin-top: 16px;
}
</style>
</head>
<body>
<h1>GameAI</h1>
<p>
You can type either:
<br>- plain text
<br>- or a full JSON request
</p>
<textarea id="payload"></textarea>
<br>
<button onclick="send()">Send</button>
<pre id="output">No response yet.</pre>
<script>
async function send() {
const raw = document.getElementById("payload").value.trim();
const output = document.getElementById("output");
let payload;
try {
if (raw.startsWith("{")) {
payload = JSON.parse(raw);
} else {
payload = {
message: raw,
chat_history: [],
tone: 0.5,
verbosity: 0.5,
transparency: 0.5
};
}
} catch (e) {
output.textContent = "Invalid JSON: " + e.message;
return;
}
output.textContent = "Sending...";
try {
const res = await fetch("/chat", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(payload)
});
const text = await res.text();
try {
const json = JSON.parse(text);
output.textContent = JSON.stringify(json, null, 2);
} catch {
output.textContent = text;
}
} catch (e) {
output.textContent = "Request failed: " + e.message;
}
}
</script>
</body>
</html>
"""