iukhan commited on
Commit
1f91055
·
verified ·
1 Parent(s): 9c994f9

Create html.html

Browse files
Files changed (1) hide show
  1. html.html +59 -0
html.html ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Word Cloud Generator</title>
7
+ </head>
8
+ <body>
9
+ <h1>Word Cloud Generator</h1>
10
+ <input type="file" id="file-upload">
11
+ <canvas id="word-cloud"></canvas>
12
+ <div id="download-container"></div>
13
+ <script>
14
+ const fileUpload = document.getElementById('file-upload');
15
+ const wordCloudCanvas = document.getElementById('word-cloud');
16
+ const downloadContainer = document.getElementById('download-container');
17
+
18
+ fileUpload.addEventListener('change', async (event) => {
19
+ const file = event.target.files[0];
20
+ const formData = new FormData();
21
+ formData.append('file', file);
22
+
23
+ const response = await fetch('/api/generate-wordcloud', {
24
+ method: 'POST',
25
+ body: formData
26
+ });
27
+
28
+ if (response.ok) {
29
+ const wordCloudData = await response.json();
30
+ // Use a library like WordCloud.js to generate the word cloud
31
+ // based on the received wordCloudData
32
+ const wordcloud = new WordCloud(wordCloudCanvas);
33
+ wordcloud.generate(wordCloudData);
34
+
35
+ // Create download links for different formats
36
+ const downloadLinks = [
37
+ { format: 'png', label: 'Download as PNG' },
38
+ { format: 'jpeg', label: 'Download as JPEG' },
39
+ ];
40
+
41
+ const downloadList = document.createElement('ul');
42
+ downloadLinks.forEach(link => {
43
+ const listItem = document.createElement('li');
44
+ const downloadLink = document.createElement('a');
45
+ downloadLink.href = `/api/download-wordcloud?format=${link.format}`; // Replace with actual API endpoint
46
+ downloadLink.textContent = link.label;
47
+ listItem.appendChild(downloadLink);
48
+ downloadList.appendChild(listItem);
49
+ });
50
+
51
+ downloadContainer.innerHTML = '';
52
+ downloadContainer.appendChild(downloadList);
53
+ } else {
54
+ console.error('Error generating word cloud');
55
+ }
56
+ });
57
+ </script>
58
+ </body>
59
+ </html>