File size: 5,891 Bytes
a8f0097
 
 
 
 
 
ebb1c1c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a8f0097
 
 
 
7a826c8
 
 
a8f0097
 
 
 
 
 
ebb1c1c
a8f0097
 
 
ebb1c1c
7a826c8
 
a8f0097
 
 
 
 
7a826c8
a8f0097
7a826c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a8f0097
7a826c8
 
a8f0097
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>File Upload with Progress</title>
    <style>
        /* General dark theme */
        * {
            box-sizing: border-box;
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
        }
        
        body {
            background-color: #121212;
            color: #e0e0e0;
            display: flex;
            flex-direction: column;
            align-items: center;
            padding: 40px;
            min-height: 100vh;
        }

        h2 {
            font-size: 1.8rem;
            color: #ffffff;
            margin-bottom: 20px;
        }

        form {
            background: #1e1e1e;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0px 4px 12px rgba(0, 0, 0, 0.3);
            width: 100%;
            max-width: 400px;
        }

        label {
            color: #bdbdbd;
            font-weight: bold;
            display: block;
            margin-top: 15px;
        }

        input[type="password"],
        input[type="text"],
        input[type="file"] {
            background: #333;
            color: #e0e0e0;
            border: none;
            border-radius: 4px;
            padding: 10px;
            width: 100%;
            margin-top: 5px;
            outline: none;
            transition: border 0.3s ease;
        }

        input[type="password"]:focus,
        input[type="text"]:focus,
        input[type="file"]:focus {
            border: 1px solid #4f8cff;
        }

        button {
            background-color: #4f8cff;
            color: #fff;
            padding: 10px 20px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            margin-top: 20px;
            width: 100%;
            transition: background 0.3s;
            font-weight: bold;
        }

        button:hover {
            background-color: #3571db;
        }

        /* Progress Section */
        #progress {
            margin-top: 20px;
            width: 100%;
            max-width: 400px;
            text-align: left;
        }

        #progress h3 {
            font-size: 1.4rem;
            margin-bottom: 10px;
        }

        pre {
            background: #212121;
            color: #bdbdbd;
            padding: 12px;
            border-radius: 6px;
            font-size: 0.9rem;
            overflow: auto;
            margin-top: 5px;
        }
    </style>
</head>
<body>
    <h2>Upload Files to Hugging Face Repository</h2>
    <form id="uploadForm" enctype="multipart/form-data">
        <label for="access_key">Access Key:</label>
        <input type="password" id="access_key" name="access_key" required>
        
        <label for="destination_folder">Destination Folder:</label>
        <input type="text" id="destination_folder" name="destination_folder" required>
        
        <label for="files">Select Files:</label>
        <input type="file" id="files" name="files" multiple required>

        <button type="submit">Upload Files</button>
    </form>
    
    <div id="progress">
        <h3>Upload Progress</h3>
        <pre id="clientProgressText">Client to Server: No upload in progress...</pre>
        <pre id="serverProgressText">Server to Storage: No upload in progress...</pre>
    </div>

    <script>
        document.getElementById("uploadForm").onsubmit = async function(event) {
            event.preventDefault();

            const formData = new FormData(this);
            const clientProgressText = document.getElementById("clientProgressText");
            const serverProgressText = document.getElementById("serverProgressText");

            // Reset progress text
            clientProgressText.textContent = "Client to Server: Starting upload...";
            serverProgressText.textContent = "Server to Storage: No upload in progress...";

            // Create XMLHttpRequest to track client-to-server upload progress
            const xhr = new XMLHttpRequest();
            xhr.open("POST", "/upload", true);

            // Add a progress event listener to track the upload to the server
            xhr.upload.onprogress = function(event) {
                if (event.lengthComputable) {
                    const percentComplete = (event.loaded / event.total) * 100;
                    clientProgressText.textContent = `Client to Server: ${percentComplete.toFixed(2)}% uploaded`;
                }
            };

            // Handle server response
            xhr.onload = async function() {
                if (xhr.status === 200) {
                    const result = JSON.parse(xhr.responseText);
                    const statusId = result.status_id;

                    // Start polling for server-to-storage progress
                    serverProgressText.textContent = "Server to Storage: Starting upload...";
                    const intervalId = setInterval(async () => {
                        const progressResponse = await fetch(`/progress/${statusId}`);
                        if (progressResponse.ok) {
                            const progressResult = await progressResponse.json();
                            serverProgressText.textContent = progressResult.progress.join("");
                        } else {
                            clearInterval(intervalId);
                            serverProgressText.textContent += "\nServer to Storage: Upload completed or status not found.";
                        }
                    }, 2000);
                } else {
                    clientProgressText.textContent = "Client to Server: Upload failed.";
                }
            };

            // Send the request
            xhr.send(formData);
        };
    </script>
</body>
</html>