Spaces:
Running
Running
Update index.js
Browse files
index.js
CHANGED
|
@@ -1,79 +1,50 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
const
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
status.textContent = 'Loading model...';
|
| 16 |
-
const detector = await pipeline('object-detection', 'Xenova/detr-resnet-50');
|
| 17 |
-
status.textContent = 'Ready';
|
| 18 |
-
|
| 19 |
-
example.addEventListener('click', (e) => {
|
| 20 |
-
e.preventDefault();
|
| 21 |
-
detect(EXAMPLE_URL);
|
| 22 |
-
});
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
}
|
| 29 |
-
|
| 30 |
-
const reader = new FileReader();
|
| 31 |
-
|
| 32 |
-
// Set up a callback when the file is loaded
|
| 33 |
-
reader.onload = e2 => detect(e2.target.result);
|
| 34 |
-
|
| 35 |
-
reader.readAsDataURL(file);
|
| 36 |
});
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
// Detect objects in the image
|
| 40 |
-
async function detect(img) {
|
| 41 |
-
imageContainer.innerHTML = '';
|
| 42 |
-
imageContainer.style.backgroundImage = `url(${img})`;
|
| 43 |
-
|
| 44 |
-
status.textContent = 'Analysing...';
|
| 45 |
-
const output = await detector(img, {
|
| 46 |
-
threshold: 0.5,
|
| 47 |
-
percentage: true,
|
| 48 |
-
});
|
| 49 |
-
status.textContent = '';
|
| 50 |
-
output.forEach(renderBox);
|
| 51 |
-
}
|
| 52 |
-
|
| 53 |
-
// Render a bounding box and label on the image
|
| 54 |
-
function renderBox({ box, label }) {
|
| 55 |
-
const { xmax, xmin, ymax, ymin } = box;
|
| 56 |
-
|
| 57 |
-
// Generate a random color for the box
|
| 58 |
-
const color = '#' + Math.floor(Math.random() * 0xFFFFFF).toString(16).padStart(6, 0);
|
| 59 |
-
|
| 60 |
-
// Draw the box
|
| 61 |
-
const boxElement = document.createElement('div');
|
| 62 |
-
boxElement.className = 'bounding-box';
|
| 63 |
-
Object.assign(boxElement.style, {
|
| 64 |
-
borderColor: color,
|
| 65 |
-
left: 100 * xmin + '%',
|
| 66 |
-
top: 100 * ymin + '%',
|
| 67 |
-
width: 100 * (xmax - xmin) + '%',
|
| 68 |
-
height: 100 * (ymax - ymin) + '%',
|
| 69 |
-
})
|
| 70 |
-
|
| 71 |
-
// Draw label
|
| 72 |
-
const labelElement = document.createElement('span');
|
| 73 |
-
labelElement.textContent = label;
|
| 74 |
-
labelElement.className = 'bounding-box-label';
|
| 75 |
-
labelElement.style.backgroundColor = color;
|
| 76 |
-
|
| 77 |
-
boxElement.appendChild(labelElement);
|
| 78 |
-
imageContainer.appendChild(boxElement);
|
| 79 |
-
}
|
|
|
|
| 1 |
+
$(document).ready(function() {
|
| 2 |
+
const messagesDiv = $('#messages');
|
| 3 |
+
const userInput = $('#userInput');
|
| 4 |
+
const sendBtn = $('#sendBtn');
|
| 5 |
+
const chartCanvas = $('#chart');
|
| 6 |
+
|
| 7 |
+
sendBtn.on('click', function() {
|
| 8 |
+
const userMessage = userInput.val();
|
| 9 |
+
if (userMessage) {
|
| 10 |
+
messagesDiv.append(`<div><strong>You:</strong> ${userMessage}</div>`);
|
| 11 |
+
userInput.val('');
|
| 12 |
+
generateChart(userMessage);
|
| 13 |
+
}
|
| 14 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
function generateChart(query) {
|
| 17 |
+
// Simulate AI response and chart generation
|
| 18 |
+
messagesDiv.append(`<div><strong>AI:</strong> Generating chart for "${query}"...</div>`);
|
| 19 |
+
|
| 20 |
+
// Simulated data for the chart
|
| 21 |
+
const labels = ['January', 'February', 'March', 'April', 'May', 'June', 'July'];
|
| 22 |
+
const data = [65, 59, 80, 81, 56, 55, 40];
|
| 23 |
+
|
| 24 |
+
// Create the chart
|
| 25 |
+
const ctx = chartCanvas[0].getContext('2d');
|
| 26 |
+
const chart = new Chart(ctx, {
|
| 27 |
+
type: 'line',
|
| 28 |
+
data: {
|
| 29 |
+
labels: labels,
|
| 30 |
+
datasets: [{
|
| 31 |
+
label: 'Stock Trend',
|
| 32 |
+
data: data,
|
| 33 |
+
borderColor: 'rgba(75, 192, 192, 1)',
|
| 34 |
+
borderWidth: 2,
|
| 35 |
+
fill: false
|
| 36 |
+
}]
|
| 37 |
+
},
|
| 38 |
+
options: {
|
| 39 |
+
responsive: true,
|
| 40 |
+
scales: {
|
| 41 |
+
y: {
|
| 42 |
+
beginAtZero: true
|
| 43 |
+
}
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
});
|
| 47 |
+
|
| 48 |
+
chartCanvas.show();
|
| 49 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|