Subham9126 commited on
Commit
3aeff5a
·
verified ·
1 Parent(s): 5969f74

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +208 -41
index.html CHANGED
@@ -23,53 +23,113 @@
23
  0% { opacity: 0; }
24
  100% { opacity: 1; }
25
  }
 
 
 
 
 
 
26
  </style>
27
  </head>
28
 
29
  <body class="bg-gray-50 min-h-screen font-sans text-gray-800">
30
- <div class="container mx-auto px-4 py-12">
 
 
 
31
 
32
- <!-- Query Input -->
33
- <div class="sticky-query bg-white rounded-lg shadow-lg p-8 mb-12">
34
- <div class="mb-6">
35
- <label for="query" class="block text-lg font-medium text-gray-700 mb-2">Query</label>
36
- <input type="text" id="query" placeholder="Enter your query" class="w-full px-4 py-3 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
 
 
 
 
 
 
 
 
 
 
37
  </div>
38
- </div>
39
 
40
- <!-- Section 1: Input -->
41
- <div class="bg-white rounded-lg shadow-lg p-8 mb-12">
42
- <div class="mb-6">
43
- <label for="given_facet" class="block text-lg font-medium text-gray-700 mb-2">Given Facet</label>
44
- <input type="text" id="given_facet" placeholder="Enter your facet in Python dictionary format" class="w-full px-4 py-3 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
45
  </div>
46
- <div class="mb-6">
47
- <label class="block text-lg font-medium text-gray-700 mb-2">Processing Method</label>
48
- <div class="flex items-center space-x-4">
49
- <label class="inline-flex items-center">
50
- <input type="radio" name="processingMethod" value="v1" checked class="form-radio h-5 w-5 text-blue-600">
51
- <span class="ml-2">V1 (Original)</span>
52
- </label>
53
- <label class="inline-flex items-center">
54
- <input type="radio" name="processingMethod" value="v2" class="form-radio h-5 w-5 text-blue-600">
55
- <span class="ml-2">V2 (New)</span>
56
- </label>
 
 
 
 
 
 
57
  </div>
 
 
 
 
 
 
58
  </div>
59
- <button id="submit" class="w-full bg-blue-600 text-white py-3 px-6 rounded-md hover:bg-blue-700 transition duration-300 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2">Submit</button>
60
  </div>
61
 
62
- <!-- Section 2: Dynamic Boxes -->
63
- <div id="dynamicBoxes" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8"></div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
 
65
- <!-- Get List Button -->
66
- <div class="mt-12 text-center">
67
- <button id="getList" class="bg-green-600 text-white py-3 px-8 rounded-md hover:bg-green-700 transition duration-300 focus:outline-none focus:ring-2 focus:ring-green-500 focus:ring-offset-2">Get List</button>
68
- <button id="reset" class="bg-red-600 text-white py-3 px-8 ml-4 rounded-md hover:bg-red-700 transition duration-300 focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2">Reset</button>
69
- </div>
70
 
71
- <!-- Result Display -->
72
- <div id="result" class="mt-12 text-center text-2xl font-semibold"></div>
 
 
 
 
 
 
 
73
  </div>
74
 
75
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
@@ -77,12 +137,10 @@
77
  $(document).ready(function() {
78
  let isResultShown = false;
79
  let facetData = [];
80
-
81
  $('#submit').click(function() {
82
  const query = $('#query').val();
83
  const givenFacet = $('#given_facet').val();
84
  const processingMethod = $('input[name="processingMethod"]:checked').val();
85
-
86
  try {
87
  if (processingMethod === 'v1') {
88
  facetData = eval('(' + givenFacet + ')');
@@ -109,7 +167,6 @@
109
  createBox(key, values, index);
110
  });
111
  }
112
-
113
  function createBox(key, values, index = null) {
114
  const $box = $('<div>').addClass('bg-white rounded-lg shadow-md p-6 fade-in');
115
  const $title = $('<div>').addClass('flex items-center justify-between mb-4')
@@ -132,7 +189,6 @@
132
  $('#getList').click(function() {
133
  const processingMethod = $('input[name="processingMethod"]:checked').val();
134
  let result;
135
-
136
  if (processingMethod === 'v1') {
137
  result = $('input[type="checkbox"]:checked').map(function() {
138
  return `'${this.name}'`;
@@ -147,12 +203,10 @@
147
  return acc;
148
  }, []);
149
  }
150
-
151
  const formattedResult = `[${result.join(', ')}]`;
152
  $('#result').text(formattedResult).addClass('fade-in');
153
  isResultShown = true;
154
  });
155
-
156
  $('#reset').click(function() {
157
  $('input[type="checkbox"]').prop('checked', false);
158
  if (isResultShown) {
@@ -160,12 +214,125 @@
160
  isResultShown = false;
161
  }
162
  });
163
-
164
  function resetResult() {
165
  $('#result').text('').removeClass('fade-in');
166
  isResultShown = false;
167
  }
168
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  </script>
170
  </body>
171
- </html>
 
23
  0% { opacity: 0; }
24
  100% { opacity: 1; }
25
  }
26
+ .sticky-sidebar {
27
+ position: sticky;
28
+ top: 0;
29
+ height: 100vh;
30
+ overflow-y: auto;
31
+ }
32
  </style>
33
  </head>
34
 
35
  <body class="bg-gray-50 min-h-screen font-sans text-gray-800">
36
+ <div class="container mx-auto px-4 py-12 flex">
37
+ <!-- Sidebar Content -->
38
+ <div class="w-1/4 sticky-sidebar bg-white rounded-lg shadow-md p-6">
39
+ <h1 class="text-2xl font-bold mb-6 text-center">Dynamic Input Form</h1>
40
 
41
+ <!-- Input for API query -->
42
+ <div class="mb-4">
43
+ <input type="text" id="queryInput" class="form-control border border-gray-300 p-2 rounded-md w-full" placeholder="Enter your query" />
44
+ <button type="button" class="btn btn-info mt-2 w-full flex items-center justify-center" onclick="fetchSuggestion()">
45
+ <svg class="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
46
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 21a2 2 0 01-2-2V5a2 2 0 012-2h6a2 2 0 012 2v14a2 2 0 01-2 2h-6z"></path>
47
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 14a2 2 0 100-4 2 2 0 000 4z"></path>
48
+ </svg>
49
+ Suggestion
50
+ </button>
51
+ </div>
52
+
53
+ <!-- Input for API key -->
54
+ <div class="mb-4">
55
+ <input type="password" id="apiKeyInput" class="form-control border border-gray-300 p-2 rounded-md w-full" placeholder="Enter your API key" />
56
  </div>
 
57
 
58
+ <!-- Loading Indicator -->
59
+ <div id="loadingIndicator" class="mb-4 hidden">
60
+ <div class="spinner-border animate-spin inline-block w-8 h-8 border-4 rounded-full" role="status"></div>
 
 
61
  </div>
62
+
63
+ <form id="dynamicForm" class="space-y-4">
64
+ <div id="inputContainer" class="space-y-4">
65
+ <!-- Initial Input Box -->
66
+ <div class="flex items-center space-x-2">
67
+ <input type="text" class="form-control border border-gray-300 p-2 rounded-md flex-grow" placeholder="Enter value">
68
+ <button type="button" class="btn btn-danger delete-btn" onclick="deleteInput(this)" disabled>
69
+ <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
70
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"></path>
71
+ </svg>
72
+ </button>
73
+ </div>
74
+ </div>
75
+ <div class="flex justify-between space-x-4">
76
+ <button type="button" class="btn btn-primary" onclick="addInput()">Add Input Box</button>
77
+ <button type="submit" class="btn btn-success">Submit</button>
78
+ <button type="button" class="btn btn-secondary" onclick="resetForm()">Reset</button>
79
  </div>
80
+ </form>
81
+
82
+ <!-- Output container -->
83
+ <div id="output" class="mt-6 p-4 bg-gray-200 rounded-md hidden">
84
+ <h2 class="text-lg font-semibold mb-2">Output:</h2>
85
+ <pre id="formattedOutput" class="text-gray-800 font-mono whitespace-pre-wrap"></pre>
86
  </div>
 
87
  </div>
88
 
89
+ <!-- Main Content -->
90
+ <div class="w-3/4 pl-4">
91
+ <!-- Query Input -->
92
+ <div class="sticky-query bg-white rounded-lg shadow-lg p-8 mb-12">
93
+ <div class="mb-6">
94
+ <label for="query" class="block text-lg font-medium text-gray-700 mb-2">Query</label>
95
+ <input type="text" id="query" placeholder="Enter your query" class="w-full px-4 py-3 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
96
+ </div>
97
+ </div>
98
+
99
+ <!-- Section 1: Input -->
100
+ <div class="bg-white rounded-lg shadow-lg p-8 mb-12">
101
+ <div class="mb-6">
102
+ <label for="given_facet" class="block text-lg font-medium text-gray-700 mb-2">Given Facet</label>
103
+ <input type="text" id="given_facet" placeholder="Enter your facet in Python dictionary format" class="w-full px-4 py-3 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
104
+ </div>
105
+ <div class="mb-6">
106
+ <label class="block text-lg font-medium text-gray-700 mb-2">Processing Method</label>
107
+ <div class="flex items-center space-x-4">
108
+ <label class="inline-flex items-center">
109
+ <input type="radio" name="processingMethod" value="v1" checked class="form-radio h-5 w-5 text-blue-600">
110
+ <span class="ml-2">V1 (Original)</span>
111
+ </label>
112
+ <label class="inline-flex items-center">
113
+ <input type="radio" name="processingMethod" value="v2" class="form-radio h-5 w-5 text-blue-600">
114
+ <span class="ml-2">V2 (New)</span>
115
+ </label>
116
+ </div>
117
+ </div>
118
+ <button id="submit" class="w-full bg-blue-600 text-white py-3 px-6 rounded-md hover:bg-blue-700 transition duration-300 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2">Submit</button>
119
+ </div>
120
 
121
+ <!-- Section 2: Dynamic Boxes -->
122
+ <div id="dynamicBoxes" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8"></div>
 
 
 
123
 
124
+ <!-- Get List Button -->
125
+ <div class="mt-12 text-center">
126
+ <button id="getList" class="bg-green-600 text-white py-3 px-8 rounded-md hover:bg-green-700 transition duration-300 focus:outline-none focus:ring-2 focus:ring-green-500 focus:ring-offset-2">Get List</button>
127
+ <button id="reset" class="bg-red-600 text-white py-3 px-8 ml-4 rounded-md hover:bg-red-700 transition duration-300 focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2">Reset</button>
128
+ </div>
129
+
130
+ <!-- Result Display -->
131
+ <div id="result" class="mt-12 text-center text-2xl font-semibold"></div>
132
+ </div>
133
  </div>
134
 
135
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
 
137
  $(document).ready(function() {
138
  let isResultShown = false;
139
  let facetData = [];
 
140
  $('#submit').click(function() {
141
  const query = $('#query').val();
142
  const givenFacet = $('#given_facet').val();
143
  const processingMethod = $('input[name="processingMethod"]:checked').val();
 
144
  try {
145
  if (processingMethod === 'v1') {
146
  facetData = eval('(' + givenFacet + ')');
 
167
  createBox(key, values, index);
168
  });
169
  }
 
170
  function createBox(key, values, index = null) {
171
  const $box = $('<div>').addClass('bg-white rounded-lg shadow-md p-6 fade-in');
172
  const $title = $('<div>').addClass('flex items-center justify-between mb-4')
 
189
  $('#getList').click(function() {
190
  const processingMethod = $('input[name="processingMethod"]:checked').val();
191
  let result;
 
192
  if (processingMethod === 'v1') {
193
  result = $('input[type="checkbox"]:checked').map(function() {
194
  return `'${this.name}'`;
 
203
  return acc;
204
  }, []);
205
  }
 
206
  const formattedResult = `[${result.join(', ')}]`;
207
  $('#result').text(formattedResult).addClass('fade-in');
208
  isResultShown = true;
209
  });
 
210
  $('#reset').click(function() {
211
  $('input[type="checkbox"]').prop('checked', false);
212
  if (isResultShown) {
 
214
  isResultShown = false;
215
  }
216
  });
 
217
  function resetResult() {
218
  $('#result').text('').removeClass('fade-in');
219
  isResultShown = false;
220
  }
221
  });
222
+
223
+ // Add input field
224
+ function addInput() {
225
+ const container = document.getElementById('inputContainer');
226
+ const newInput = document.createElement('div');
227
+ newInput.className = 'flex items-center space-x-2';
228
+ newInput.innerHTML = `
229
+ <input type="text" class="form-control border border-gray-300 p-2 rounded-md flex-grow" placeholder="Enter value">
230
+ <button type="button" class="btn btn-danger delete-btn" onclick="deleteInput(this)">
231
+ <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
232
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"></path>
233
+ </svg>
234
+ </button>
235
+ `;
236
+ container.appendChild(newInput);
237
+ updateDeleteButtons();
238
+ }
239
+ // Delete input field
240
+ function deleteInput(button) {
241
+ button.parentElement.remove();
242
+ updateDeleteButtons();
243
+ }
244
+ // Update delete button states
245
+ function updateDeleteButtons() {
246
+ const deleteButtons = document.querySelectorAll('.delete-btn');
247
+ deleteButtons.forEach(btn => {
248
+ btn.disabled = deleteButtons.length === 1;
249
+ });
250
+ }
251
+ // Reset form
252
+ function resetForm() {
253
+ const container = document.getElementById('inputContainer');
254
+ container.innerHTML = `
255
+ <div class="flex items-center space-x-2">
256
+ <input type="text" class="form-control border border-gray-300 p-2 rounded-md flex-grow" placeholder="Enter value">
257
+ <button type="button" class="btn btn-danger delete-btn" onclick="deleteInput(this)" disabled>
258
+ <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
259
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"></path>
260
+ </svg>
261
+ </button>
262
+ </div>
263
+ `;
264
+ document.getElementById('output').classList.add('hidden');
265
+ document.getElementById('formattedOutput').textContent = '';
266
+ }
267
+ // Process input value (trim, lowercase, replace spaces with underscores)
268
+ function processInputValue(value) {
269
+ return value.trim().toLowerCase().replace(/\s+/g, '_');
270
+ }
271
+ // Submit form event
272
+ document.getElementById('dynamicForm').addEventListener('submit', function(e) {
273
+ e.preventDefault();
274
+ const inputs = document.querySelectorAll('#inputContainer input');
275
+ const values = Array.from(inputs).map(input => processInputValue(input.value));
276
+ const formattedOutput = `[${result.join(', ')}]`;
277
+ document.getElementById('formattedOutput').textContent = formattedOutput;
278
+ document.getElementById('output').classList.remove('hidden');
279
+ });
280
+ // Fetch suggestion from the API and dynamically adjust the input boxes
281
+ async function fetchSuggestion() {
282
+ const queryValue = document.getElementById('queryInput').value;
283
+ const apiKey = document.getElementById('apiKeyInput').value;
284
+ if (!queryValue) {
285
+ alert("Please enter a query!");
286
+ return;
287
+ }
288
+ if (!apiKey) {
289
+ alert("Please enter your API key!");
290
+ return;
291
+ }
292
+ // Show loading indicator
293
+ document.getElementById('loadingIndicator').classList.remove('hidden');
294
+ // Clear previous inputs
295
+ resetForm();
296
+ const data = {
297
+ question: queryValue
298
+ };
299
+ try {
300
+ const response = await fetch('https://subham9126-hfflow.hf.space/api/v1/prediction/447aeeb8-3505-47ac-84c5-6a1e72454f80', {
301
+ method: "POST",
302
+ headers: {
303
+ "Authorization": `Bearer ${apiKey}`,
304
+ "Content-Type": "application/json"
305
+ },
306
+ body: JSON.stringify(data)
307
+ });
308
+ if (!response.ok) {
309
+ throw new Error("Error fetching suggestion");
310
+ }
311
+ const result = await response.json();
312
+ const attributes = result.json.attributes; // Get attributes from response
313
+ const inputContainer = document.getElementById('inputContainer');
314
+ const currentInputCount = document.querySelectorAll('#inputContainer input').length;
315
+ // If the number of attributes is greater than current input boxes, add more boxes
316
+ if (attributes.length > currentInputCount) {
317
+ for (let i = currentInputCount; i < attributes.length; i++) {
318
+ addInput();
319
+ }
320
+ }
321
+ // Update the values of the input boxes to match the attributes
322
+ const inputs = document.querySelectorAll('#inputContainer input');
323
+ inputs.forEach((input, index) => {
324
+ if (attributes[index]) {
325
+ input.value = attributes[index]; // Align attribute with input box
326
+ }
327
+ });
328
+ } catch (error) {
329
+ console.error("Error fetching suggestion:", error);
330
+ alert("Failed to fetch suggestions. Please check your API key or network.");
331
+ } finally {
332
+ // Hide loading indicator
333
+ document.getElementById('loadingIndicator').classList.add('hidden');
334
+ }
335
+ }
336
  </script>
337
  </body>
338
+ </html>