Spaces:
Running
Running
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> | |
<title>Web Playground</title> | |
<style> | |
* { | |
box-sizing: border-box; | |
} | |
body { | |
margin: 0; | |
font-family: system-ui, sans-serif; | |
display: flex; | |
height: 100vh; | |
background: #f5f5f5; | |
} | |
.sidebar { | |
width: 300px; | |
background: #ddd; | |
display: flex; | |
flex-direction: column; | |
justify-content: flex-end; | |
padding: 1rem; | |
border-radius: 0 0 0 30px; | |
} | |
.sidebar input { | |
border: none; | |
padding: 0.75rem 1rem; | |
border-radius: 30px; | |
margin-top: auto; | |
outline: none; | |
} | |
.main { | |
flex: 1; | |
display: flex; | |
flex-direction: column; | |
border-radius: 0 0 30px 0; | |
} | |
.tab-bar { | |
display: flex; | |
align-items: center; | |
padding: 0.5rem 1rem; | |
gap: 0.5rem; | |
background: #ccc; | |
border-radius: 0 0 0 30px; | |
} | |
.tab-bar .tab { | |
background: white; | |
border-radius: 30px; | |
padding: 0.4rem 1rem; | |
cursor: pointer; | |
border: none; | |
} | |
.tab-bar .actions { | |
margin-left: auto; | |
display: flex; | |
gap: 1rem; | |
} | |
.tab-bar .actions button { | |
background: none; | |
border: none; | |
font-weight: bold; | |
cursor: pointer; | |
} | |
.editor { | |
flex: 1; | |
background: #eee; | |
padding: 1rem; | |
} | |
textarea { | |
width: 100%; | |
height: 100%; | |
border: none; | |
outline: none; | |
background: transparent; | |
font-family: monospace; | |
font-size: 14px; | |
} | |
</style> | |
</head> | |
<body> | |
<!-- Left: Assistant --> | |
<div class="sidebar"> | |
<input id="prompt" type="text" placeholder="Write what you want ✨" /> | |
</div> | |
<!-- Right: Editor UI --> | |
<div class="main"> | |
<div class="tab-bar"> | |
<button class="tab">index.html</button> | |
<button class="tab">styles.css</button> | |
<button class="tab">script.js</button> | |
<button class="tab">+</button> | |
<div class="actions"> | |
<button>▶️ Run</button> | |
<button>Download</button> | |
</div> | |
</div> | |
<div class="editor"> | |
<textarea id="editor" placeholder="Your code..."></textarea> | |
</div> | |
</div> | |
<script> | |
const promptInput = document.getElementById("prompt"); | |
const editor = document.getElementById("editor"); | |
promptInput.addEventListener("keydown", async (e) => { | |
if (e.key === "Enter") { | |
e.preventDefault(); | |
const prompt = promptInput.value.trim(); | |
if (!prompt) return; | |
promptInput.disabled = true; | |
promptInput.value = "Thinking..."; | |
const response = await fetch("/generate", { | |
method: "POST", | |
headers: { "Content-Type": "application/json" }, | |
body: JSON.stringify({ data: [prompt] }) | |
}); | |
const json = await response.json(); | |
const aiText = json.data[0]; | |
// Append AI response to editor | |
editor.value += "\\n\\n// AI Suggestion:\\n" + aiText; | |
promptInput.value = ""; | |
promptInput.disabled = false; | |
promptInput.focus(); | |
} | |
}); | |
</script> | |
</body> | |
</html> |