Spaces:
No application file
No application file
Create index.html
Browse files- index.html +52 -0
index.html
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html>
|
| 3 |
+
<head>
|
| 4 |
+
<title>Robot Chat + TTS</title>
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
| 6 |
+
<style>
|
| 7 |
+
body { font-family: sans-serif; padding: 1rem; max-width: 600px; margin: auto; }
|
| 8 |
+
input, textarea, button { width: 100%; padding: 0.75rem; margin: 0.5rem 0; font-size: 1rem; }
|
| 9 |
+
audio { width: 100%; margin-top: 1rem; }
|
| 10 |
+
</style>
|
| 11 |
+
</head>
|
| 12 |
+
<body>
|
| 13 |
+
<h1>🤖 Robot Chat + TTS</h1>
|
| 14 |
+
|
| 15 |
+
<h2>Chatbot</h2>
|
| 16 |
+
<textarea id="chatInput" rows="3" placeholder="Ask me something..."></textarea>
|
| 17 |
+
<button onclick="sendChat()">Send</button>
|
| 18 |
+
<p><strong>Reply:</strong> <span id="chatReply">—</span></p>
|
| 19 |
+
|
| 20 |
+
<hr>
|
| 21 |
+
|
| 22 |
+
<h2>Text to Speech</h2>
|
| 23 |
+
<textarea id="ttsInput" rows="3" placeholder="Enter text to speak..."></textarea>
|
| 24 |
+
<button onclick="sendTTS()">Speak</button>
|
| 25 |
+
<audio id="ttsAudio" controls></audio>
|
| 26 |
+
|
| 27 |
+
<script>
|
| 28 |
+
async function sendChat() {
|
| 29 |
+
const prompt = document.getElementById("chatInput").value;
|
| 30 |
+
const res = await fetch("/chat", {
|
| 31 |
+
method: "POST",
|
| 32 |
+
headers: { "Content-Type": "application/json" },
|
| 33 |
+
body: JSON.stringify({ prompt })
|
| 34 |
+
});
|
| 35 |
+
const data = await res.json();
|
| 36 |
+
document.getElementById("chatReply").textContent = data.response;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
async function sendTTS() {
|
| 40 |
+
const text = document.getElementById("ttsInput").value;
|
| 41 |
+
const res = await fetch("/tts", {
|
| 42 |
+
method: "POST",
|
| 43 |
+
headers: { "Content-Type": "application/json" },
|
| 44 |
+
body: JSON.stringify({ text })
|
| 45 |
+
});
|
| 46 |
+
const blob = await res.blob();
|
| 47 |
+
const audioUrl = URL.createObjectURL(blob);
|
| 48 |
+
document.getElementById("ttsAudio").src = audioUrl;
|
| 49 |
+
}
|
| 50 |
+
</script>
|
| 51 |
+
</body>
|
| 52 |
+
</html>
|