AeroVortex commited on
Commit
01cbf71
·
verified ·
1 Parent(s): 884e5fe

Create index.html

Browse files
Files changed (1) hide show
  1. index.html +57 -19
index.html CHANGED
@@ -1,19 +1,57 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script>
2
+ // Use environment variable instead of hardcoding
3
+ const HF_TOKEN = process.env.HF_TOKEN;
4
+ const BUCKET = "aerovortex-storage";
5
+
6
+ async function uploadFile() {
7
+ const fileInput = document.getElementById('fileInput');
8
+ const file = fileInput.files[0];
9
+ if (!file) return alert("No file selected");
10
+
11
+ const url = `https://huggingface.co/api/buckets/${BUCKET}/upload/${file.name}`;
12
+ const response = await fetch(url, {
13
+ method: "PUT",
14
+ headers: { "Authorization": `Bearer ${HF_TOKEN}` },
15
+ body: file
16
+ });
17
+
18
+ if (response.ok) {
19
+ alert(`✅ Uploaded ${file.name}`);
20
+ await prewarmFile(file.name);
21
+ listFiles();
22
+ } else {
23
+ alert("❌ Upload failed");
24
+ }
25
+ }
26
+
27
+ async function listFiles() {
28
+ const url = `https://huggingface.co/api/buckets/${BUCKET}/list`;
29
+ const response = await fetch(url, {
30
+ headers: { "Authorization": `Bearer ${HF_TOKEN}` }
31
+ });
32
+ const files = await response.json();
33
+
34
+ const list = document.getElementById('fileList');
35
+ list.innerHTML = "";
36
+ files.forEach(file => {
37
+ const li = document.createElement("li");
38
+ li.className = "file-box";
39
+ li.innerHTML = `<a href="${file.url}" target="_blank">${file.name}</a>`;
40
+ list.appendChild(li);
41
+ });
42
+ }
43
+
44
+ async function prewarmFile(fileName) {
45
+ const url = `https://huggingface.co/api/buckets/${BUCKET}/prewarm`;
46
+ await fetch(url, {
47
+ method: "POST",
48
+ headers: {
49
+ "Authorization": `Bearer ${HF_TOKEN}`,
50
+ "Content-Type": "application/json"
51
+ },
52
+ body: JSON.stringify({ files: [fileName] })
53
+ });
54
+ }
55
+
56
+ listFiles();
57
+ </script>