File size: 6,718 Bytes
44ac2cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b58a04a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Chatbot Configuration</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #121212;
            color: #e0e0e0;
            margin: 0;
            padding: 20px;
        }

        h1 {
            color: #ff9800;
        }

        h2 {
            color: #ff5722;
        }

        label {
            display: block;
            margin-bottom: 8px;
            font-size: 16px;
        }

        input[type="text"] {
            width: 100%;
            padding: 10px;
            margin-bottom: 15px;
            border: none;
            border-radius: 8px;
            background-color: #333;
            color: #e0e0e0;
            font-size: 16px;
        }

        input[type="text"]:focus {
            outline: none;
            background-color: #444;
        }

        button {
            background-color: #6200ea;
            color: #fff;
            border: none;
            border-radius: 8px;
            padding: 10px 20px;
            margin: 5px;
            font-size: 16px;
            cursor: pointer;
            transition: background-color 0.3s, transform 0.2s;
        }

        button:hover {
            background-color: #3700b3;
        }

        button:active {
            transform: scale(0.98);
        }

        #loadingNotification {
            display: none; /* Hidden by default */
            position: fixed;
            top: 20px;
            left: 50%;
            transform: translateX(-50%);
            background-color: #000;
            color: #ff5722;
            padding: 15px 30px;
            border-radius: 20px;
            font-size: 18px;
            z-index: 1000;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            animation: fadeInOut 2s infinite;
        }

        @keyframes fadeInOut {
            0% { opacity: 0; }
            50% { opacity: 1; }
            100% { opacity: 0; }
        }

        #output {
            background-color: #222;
            color: #e0e0e0;
            padding: 10px;
            border-radius: 8px;
            font-size: 16px;
        }
    </style>
</head>
<body>
    <h1>Chatbot Configuration</h1>
    <div id="loadingNotification">Loading...</div>

    <label for="character">Chatbot Character:</label>
    <input type="text" id="character">
    
    <label for="knowledge">Chatbot Knowledge:</label>
    <input type="text" id="knowledge">
    
    <label for="style">Chatbot Chatting Style:</label>
    <input type="text" id="style">
    
    <button id="getCharacter">Get Character</button>
    <button id="getKnowledge">Get Knowledge</button>
    <button id="getStyle">Get Style</button>
    <button id="submit">Submit</button>
    
    <h2>Output</h2>
    <p id="output"></p>


    <script type="module">
	const outputElement = document.getElementById('output');
        const loadingNotification = document.getElementById('loadingNotification');
	showLoading()
	
        import { client } from "https://cdn.jsdelivr.net/npm/@gradio/client@latest";

        const app = await client("NihalGazi/Jeni-bot");

        
		
		getData();
		console.log("ok");

        function showLoading() {
            loadingNotification.style.display = 'block';
        }

        function hideLoading() {
            loadingNotification.style.display = 'none';
        }
		
		
		async function getData() {
		
		
            try {
                const result = await app.predict("/on_get_character", []);
                document.getElementById("character").value = result.data[0];
            } finally {
					try {
						const result = await app.predict("/on_get_knowledge", []);
						document.getElementById("knowledge").value = result.data[0];
					} finally {
						try {
							const result = await app.predict("/on_get_style", []);
							document.getElementById("style").value = result.data[0];
						} finally {
							hideLoading();
						}
					}
					
            }
        }
		
		

        async function getCharacter() {
            showLoading();
            try {
                const result = await app.predict("/on_get_character", []);
                outputElement.textContent = result.data[0];
            } finally {
                hideLoading();
            }
        }

        async function getKnowledge() {
            showLoading();
            try {
                const result = await app.predict("/on_get_knowledge", []);
                outputElement.textContent = result.data[0];
            } finally {
                hideLoading();
            }
        }

        async function getStyle() {
            showLoading();
            try {
                const result = await app.predict("/on_get_style", []);
                outputElement.textContent = result.data[0];
            } finally {
                hideLoading();
            }
        }

        async function submitConfig() {
            showLoading();
            try {
                const character = document.getElementById('character').value;
                const knowledge = document.getElementById('knowledge').value;
                const style = document.getElementById('style').value;

                const result = await app.predict("/on_submit", [character, knowledge, style]);
                outputElement.textContent = "Updated successfully!";
            } finally {
                hideLoading();
            }
        }

        async function fetchInitialValues() {
            showLoading();
            try {
                const characterResult = await app.predict("/on_get_character", []);
                const knowledgeResult = await app.predict("/on_get_knowledge", []);
                const styleResult = await app.predict("/on_get_style", []);

                document.getElementById('character').value = characterResult.data[0];
                document.getElementById('knowledge').value = knowledgeResult.data[0];
                document.getElementById('style').value = styleResult.data[0];
            } finally {
                hideLoading();
            }
        }

        document.getElementById('getCharacter').addEventListener('click', getCharacter);
        document.getElementById('getKnowledge').addEventListener('click', getKnowledge);
        document.getElementById('getStyle').addEventListener('click', getStyle);
        document.getElementById('submit').addEventListener('click', submitConfig);

        // Fetch initial values before page loads
        window.addEventListener('load', fetchInitialValues);
    </script>
</body>
</html>