Spaces:
Runtime error
Runtime error
Update templates/index.html
Browse files- templates/index.html +77 -78
templates/index.html
CHANGED
@@ -3,108 +3,107 @@
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
-
<title>
|
|
|
|
|
7 |
<style>
|
8 |
body {
|
9 |
font-family: Arial, sans-serif;
|
10 |
margin: 0;
|
11 |
padding: 0;
|
12 |
-
|
13 |
-
flex-direction: column;
|
14 |
-
align-items: center;
|
15 |
-
background-color: #f4f4f9;
|
16 |
}
|
17 |
-
|
|
|
18 |
max-width: 800px;
|
19 |
-
|
|
|
20 |
padding: 20px;
|
21 |
-
|
22 |
-
|
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 |
-
|
39 |
-
|
40 |
-
font-weight: bold;
|
41 |
-
color: #333;
|
42 |
-
}
|
43 |
-
.code-editor {
|
44 |
width: 100%;
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
font-family: monospace;
|
49 |
-
margin-bottom: 15px;
|
50 |
}
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
padding: 10px 15px;
|
56 |
-
border-radius: 5px;
|
57 |
-
cursor: pointer;
|
58 |
}
|
59 |
-
|
60 |
-
|
|
|
61 |
}
|
62 |
</style>
|
63 |
</head>
|
64 |
<body>
|
65 |
-
<div
|
66 |
-
<h1>
|
67 |
-
<
|
68 |
-
<textarea id="
|
69 |
-
|
70 |
-
<
|
71 |
-
|
72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
</div>
|
74 |
</div>
|
75 |
-
<script>
|
76 |
-
let history = [];
|
77 |
|
78 |
-
|
79 |
-
|
80 |
-
|
|
|
|
|
|
|
81 |
|
82 |
-
|
|
|
|
|
|
|
|
|
|
|
83 |
|
84 |
-
|
85 |
-
document.getElementById("user-input").value = '';
|
86 |
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
body: JSON.stringify({
|
91 |
message: message,
|
|
|
|
|
|
|
92 |
history: history,
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
});
|
107 |
-
}
|
108 |
</script>
|
109 |
</body>
|
110 |
</html>
|
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Custom AI App</title>
|
7 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/1.4.0/axios.min.js"></script>
|
8 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.14/ace.js"></script>
|
9 |
<style>
|
10 |
body {
|
11 |
font-family: Arial, sans-serif;
|
12 |
margin: 0;
|
13 |
padding: 0;
|
14 |
+
background: #f4f4f4;
|
|
|
|
|
|
|
15 |
}
|
16 |
+
|
17 |
+
#app-container {
|
18 |
max-width: 800px;
|
19 |
+
margin: 50px auto;
|
20 |
+
background: #fff;
|
21 |
padding: 20px;
|
22 |
+
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
23 |
+
border-radius: 10px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
}
|
25 |
+
|
26 |
+
textarea, input, button {
|
|
|
|
|
|
|
|
|
27 |
width: 100%;
|
28 |
+
margin: 10px 0;
|
29 |
+
padding: 10px;
|
30 |
+
font-size: 1rem;
|
|
|
|
|
31 |
}
|
32 |
+
|
33 |
+
#response {
|
34 |
+
white-space: pre-wrap;
|
35 |
+
margin-top: 20px;
|
|
|
|
|
|
|
36 |
}
|
37 |
+
|
38 |
+
#editor-container {
|
39 |
+
margin: 20px 0;
|
40 |
}
|
41 |
</style>
|
42 |
</head>
|
43 |
<body>
|
44 |
+
<div id="app-container">
|
45 |
+
<h1>Custom AI App</h1>
|
46 |
+
<label for="system_message">System Message</label>
|
47 |
+
<textarea id="system_message">You are a friendly Chatbot.</textarea>
|
48 |
+
|
49 |
+
<label for="message">Your Message</label>
|
50 |
+
<textarea id="message"></textarea>
|
51 |
+
|
52 |
+
<label for="max_tokens">Max Tokens</label>
|
53 |
+
<input type="number" id="max_tokens" value="512" min="1" max="2048">
|
54 |
+
|
55 |
+
<label for="temperature">Temperature</label>
|
56 |
+
<input type="number" id="temperature" step="0.1" value="0.7" min="0.1" max="4.0">
|
57 |
+
|
58 |
+
<label for="top_p">Top-p</label>
|
59 |
+
<input type="number" id="top_p" step="0.05" value="0.95" min="0.1" max="1.0">
|
60 |
+
|
61 |
+
<button id="submit-btn">Submit</button>
|
62 |
+
<div id="response"></div>
|
63 |
+
|
64 |
+
<h3>Code Editor</h3>
|
65 |
+
<div id="editor-container">
|
66 |
+
<div id="editor" style="height: 300px; width: 100%; border: 1px solid #ccc;"></div>
|
67 |
</div>
|
68 |
</div>
|
|
|
|
|
69 |
|
70 |
+
<script>
|
71 |
+
const submitBtn = document.getElementById("submit-btn");
|
72 |
+
const responseDiv = document.getElementById("response");
|
73 |
+
const editor = ace.edit("editor");
|
74 |
+
editor.setTheme("ace/theme/monokai");
|
75 |
+
editor.session.setMode("ace/mode/javascript");
|
76 |
|
77 |
+
submitBtn.addEventListener("click", async () => {
|
78 |
+
const systemMessage = document.getElementById("system_message").value;
|
79 |
+
const message = document.getElementById("message").value;
|
80 |
+
const maxTokens = document.getElementById("max_tokens").value;
|
81 |
+
const temperature = document.getElementById("temperature").value;
|
82 |
+
const topP = document.getElementById("top_p").value;
|
83 |
|
84 |
+
const history = []; // Include logic for maintaining chat history if needed.
|
|
|
85 |
|
86 |
+
try {
|
87 |
+
const response = await axios.post("/respond", {
|
88 |
+
system_message: systemMessage,
|
|
|
89 |
message: message,
|
90 |
+
max_tokens: parseInt(maxTokens),
|
91 |
+
temperature: parseFloat(temperature),
|
92 |
+
top_p: parseFloat(topP),
|
93 |
history: history,
|
94 |
+
});
|
95 |
+
|
96 |
+
const result = response.data.response;
|
97 |
+
responseDiv.innerHTML = `<strong>Response:</strong><br>${result.replace(
|
98 |
+
/\*\*\*(.*?)\*\*\*/g,
|
99 |
+
"<b><i>$1</i></b>"
|
100 |
+
)}`;
|
101 |
+
editor.setValue(result);
|
102 |
+
} catch (error) {
|
103 |
+
console.error(error);
|
104 |
+
responseDiv.textContent = "Error occurred while fetching the response.";
|
105 |
+
}
|
106 |
+
});
|
|
|
|
|
107 |
</script>
|
108 |
</body>
|
109 |
</html>
|