Spaces:
Runtime error
Runtime error
Create templates/index.html
Browse files- templates/index.html +110 -0
templates/index.html
ADDED
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Chatbot App</title>
|
7 |
+
<style>
|
8 |
+
body {
|
9 |
+
font-family: Arial, sans-serif;
|
10 |
+
margin: 0;
|
11 |
+
padding: 0;
|
12 |
+
display: flex;
|
13 |
+
flex-direction: column;
|
14 |
+
align-items: center;
|
15 |
+
background-color: #f4f4f9;
|
16 |
+
}
|
17 |
+
.container {
|
18 |
+
max-width: 800px;
|
19 |
+
width: 100%;
|
20 |
+
padding: 20px;
|
21 |
+
background: white;
|
22 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
23 |
+
border-radius: 8px;
|
24 |
+
margin-top: 30px;
|
25 |
+
}
|
26 |
+
.chat-box {
|
27 |
+
border: 1px solid #ddd;
|
28 |
+
border-radius: 5px;
|
29 |
+
padding: 10px;
|
30 |
+
height: 300px;
|
31 |
+
overflow-y: auto;
|
32 |
+
margin-bottom: 15px;
|
33 |
+
background-color: #f9f9f9;
|
34 |
+
}
|
35 |
+
.user-message, .bot-message {
|
36 |
+
margin: 5px 0;
|
37 |
+
}
|
38 |
+
.bot-message {
|
39 |
+
font-style: italic;
|
40 |
+
font-weight: bold;
|
41 |
+
color: #333;
|
42 |
+
}
|
43 |
+
.code-editor {
|
44 |
+
width: 100%;
|
45 |
+
height: 200px;
|
46 |
+
border: 1px solid #ddd;
|
47 |
+
border-radius: 5px;
|
48 |
+
font-family: monospace;
|
49 |
+
margin-bottom: 15px;
|
50 |
+
}
|
51 |
+
button {
|
52 |
+
background: #007bff;
|
53 |
+
color: white;
|
54 |
+
border: none;
|
55 |
+
padding: 10px 15px;
|
56 |
+
border-radius: 5px;
|
57 |
+
cursor: pointer;
|
58 |
+
}
|
59 |
+
button:hover {
|
60 |
+
background: #0056b3;
|
61 |
+
}
|
62 |
+
</style>
|
63 |
+
</head>
|
64 |
+
<body>
|
65 |
+
<div class="container">
|
66 |
+
<h1>Chatbot Interface</h1>
|
67 |
+
<div class="chat-box" id="chat-box"></div>
|
68 |
+
<textarea id="user-input" placeholder="Type your message here..." rows="3" style="width: 100%;"></textarea>
|
69 |
+
<button onclick="sendMessage()">Send</button>
|
70 |
+
<div>
|
71 |
+
<h3>Code Editor</h3>
|
72 |
+
<textarea id="code-editor" class="code-editor"></textarea>
|
73 |
+
</div>
|
74 |
+
</div>
|
75 |
+
<script>
|
76 |
+
let history = [];
|
77 |
+
|
78 |
+
function sendMessage() {
|
79 |
+
const message = document.getElementById("user-input").value;
|
80 |
+
const chatBox = document.getElementById("chat-box");
|
81 |
+
|
82 |
+
if (!message.trim()) return;
|
83 |
+
|
84 |
+
chatBox.innerHTML += `<div class="user-message"><b>User:</b> ${message}</div>`;
|
85 |
+
document.getElementById("user-input").value = '';
|
86 |
+
|
87 |
+
fetch('/get_response', {
|
88 |
+
method: 'POST',
|
89 |
+
headers: { 'Content-Type': 'application/json' },
|
90 |
+
body: JSON.stringify({
|
91 |
+
message: message,
|
92 |
+
history: history,
|
93 |
+
system_message: "You are a friendly chatbot.",
|
94 |
+
max_tokens: 512,
|
95 |
+
temperature: 0.7,
|
96 |
+
top_p: 0.95
|
97 |
+
})
|
98 |
+
})
|
99 |
+
.then(response => response.json())
|
100 |
+
.then(data => {
|
101 |
+
const botMessage = data.response;
|
102 |
+
chatBox.innerHTML += `<div class="bot-message"><b>Bot:</b> ${botMessage}</div>`;
|
103 |
+
document.getElementById("code-editor").value += botMessage + "\n";
|
104 |
+
history.push([message, botMessage]);
|
105 |
+
chatBox.scrollTop = chatBox.scrollHeight;
|
106 |
+
});
|
107 |
+
}
|
108 |
+
</script>
|
109 |
+
</body>
|
110 |
+
</html>
|