Futuresony commited on
Commit
0cbb769
·
verified ·
1 Parent(s): aa29f84

Update templates/index.html

Browse files
Files changed (1) hide show
  1. 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>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>
 
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>