coollsd commited on
Commit
260c561
1 Parent(s): 46a986e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -43
app.py CHANGED
@@ -17,7 +17,7 @@ HTML_CONTENT = """
17
  <style>
18
  body {
19
  font-family: 'Poppins', sans-serif;
20
- background: linear-gradient(135deg, #20B2AA 0%, #48D1CC 100%);
21
  height: 100vh;
22
  margin: 0;
23
  display: flex;
@@ -28,19 +28,14 @@ HTML_CONTENT = """
28
  .container {
29
  background: rgba(255, 255, 255, 0.95);
30
  padding: 2.5rem;
31
- border-radius: 20px;
32
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
33
  text-align: center;
34
  max-width: 450px;
35
  width: 100%;
36
- transition: all 0.3s ease;
37
- }
38
- .container:hover {
39
- transform: translateY(-5px);
40
- box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
41
  }
42
  h1 {
43
- color: #20B2AA;
44
  margin-bottom: 1.5rem;
45
  font-weight: 600;
46
  }
@@ -48,20 +43,20 @@ HTML_CONTENT = """
48
  display: none;
49
  }
50
  .btn {
51
- background-color: #20B2AA;
52
  color: white;
53
  padding: 12px 24px;
54
- border-radius: 30px;
55
  cursor: pointer;
56
  transition: all 0.3s ease;
57
  display: inline-block;
58
  font-weight: 600;
59
  border: none;
60
  font-size: 1rem;
 
61
  }
62
  .btn:hover {
63
- background-color: #48D1CC;
64
- transform: scale(1.05);
65
  }
66
  .btn:disabled {
67
  background-color: #ccc;
@@ -86,7 +81,7 @@ HTML_CONTENT = """
86
  .progress {
87
  width: 0%;
88
  height: 100%;
89
- background-color: #20B2AA;
90
  transition: width 0.5s ease;
91
  }
92
  .loading-spinner {
@@ -94,7 +89,7 @@ HTML_CONTENT = """
94
  width: 40px;
95
  height: 40px;
96
  border: 4px solid #f3f3f3;
97
- border-top: 4px solid #20B2AA;
98
  border-radius: 50%;
99
  animation: spin 1s linear infinite;
100
  margin: 20px auto;
@@ -108,14 +103,14 @@ HTML_CONTENT = """
108
  margin-top: 1.5rem;
109
  }
110
  .result-link {
111
- color: #20B2AA;
112
  text-decoration: none;
113
  font-weight: 600;
114
  transition: all 0.3s ease;
115
  margin-right: 10px;
116
  }
117
  .result-link:hover {
118
- color: #48D1CC;
119
  text-decoration: underline;
120
  }
121
  .copy-btn {
@@ -185,41 +180,38 @@ HTML_CONTENT = """
185
  loadingSpinner.style.display = 'block';
186
  uploadBtn.disabled = true;
187
 
188
- fetch('/upload', {
189
- method: 'POST',
190
- body: formData
191
- })
192
- .then(response => response.json())
193
- .then(data => {
194
  loadingSpinner.style.display = 'none';
195
  uploadBtn.disabled = false;
196
- if (data.url) {
197
- resultLink.href = data.url;
198
- resultLink.textContent = 'View Uploaded File';
199
- resultContainer.style.display = 'block';
 
 
 
 
 
200
  } else {
201
- alert('Upload failed: ' + data.error);
202
  }
203
- })
204
- .catch(error => {
205
  loadingSpinner.style.display = 'none';
206
  uploadBtn.disabled = false;
207
- alert('Upload failed: ' + error);
208
- });
209
-
210
- simulateProgress();
211
  }
212
 
213
- function simulateProgress() {
214
- let width = 0;
215
- const interval = setInterval(() => {
216
- if (width >= 90) {
217
- clearInterval(interval);
218
- } else {
219
- width++;
220
- progress.style.width = width + '%';
221
- }
222
- }, 50);
223
  }
224
 
225
  copyBtn.addEventListener('click', () => {
 
17
  <style>
18
  body {
19
  font-family: 'Poppins', sans-serif;
20
+ background: #008080;
21
  height: 100vh;
22
  margin: 0;
23
  display: flex;
 
28
  .container {
29
  background: rgba(255, 255, 255, 0.95);
30
  padding: 2.5rem;
31
+ border-radius: 10px;
32
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
33
  text-align: center;
34
  max-width: 450px;
35
  width: 100%;
 
 
 
 
 
36
  }
37
  h1 {
38
+ color: #008080;
39
  margin-bottom: 1.5rem;
40
  font-weight: 600;
41
  }
 
43
  display: none;
44
  }
45
  .btn {
46
+ background-color: #008080;
47
  color: white;
48
  padding: 12px 24px;
49
+ border-radius: 5px;
50
  cursor: pointer;
51
  transition: all 0.3s ease;
52
  display: inline-block;
53
  font-weight: 600;
54
  border: none;
55
  font-size: 1rem;
56
+ margin: 0.5rem;
57
  }
58
  .btn:hover {
59
+ background-color: #006666;
 
60
  }
61
  .btn:disabled {
62
  background-color: #ccc;
 
81
  .progress {
82
  width: 0%;
83
  height: 100%;
84
+ background-color: #008080;
85
  transition: width 0.5s ease;
86
  }
87
  .loading-spinner {
 
89
  width: 40px;
90
  height: 40px;
91
  border: 4px solid #f3f3f3;
92
+ border-top: 4px solid #008080;
93
  border-radius: 50%;
94
  animation: spin 1s linear infinite;
95
  margin: 20px auto;
 
103
  margin-top: 1.5rem;
104
  }
105
  .result-link {
106
+ color: #008080;
107
  text-decoration: none;
108
  font-weight: 600;
109
  transition: all 0.3s ease;
110
  margin-right: 10px;
111
  }
112
  .result-link:hover {
113
+ color: #006666;
114
  text-decoration: underline;
115
  }
116
  .copy-btn {
 
180
  loadingSpinner.style.display = 'block';
181
  uploadBtn.disabled = true;
182
 
183
+ const xhr = new XMLHttpRequest();
184
+ xhr.open('POST', '/upload', true);
185
+ xhr.upload.onprogress = updateProgress;
186
+ xhr.onload = function() {
 
 
187
  loadingSpinner.style.display = 'none';
188
  uploadBtn.disabled = false;
189
+ if (xhr.status === 200) {
190
+ const response = JSON.parse(xhr.responseText);
191
+ if (response.url) {
192
+ resultLink.href = response.url;
193
+ resultLink.textContent = 'View Uploaded File';
194
+ resultContainer.style.display = 'block';
195
+ } else {
196
+ alert('Upload failed: ' + response.error);
197
+ }
198
  } else {
199
+ alert('Upload failed: ' + xhr.statusText);
200
  }
201
+ };
202
+ xhr.onerror = function() {
203
  loadingSpinner.style.display = 'none';
204
  uploadBtn.disabled = false;
205
+ alert('Upload failed: Network error');
206
+ };
207
+ xhr.send(formData);
 
208
  }
209
 
210
+ function updateProgress(event) {
211
+ if (event.lengthComputable) {
212
+ const percentComplete = (event.loaded / event.total) * 100;
213
+ progress.style.width = percentComplete + '%';
214
+ }
 
 
 
 
 
215
  }
216
 
217
  copyBtn.addEventListener('click', () => {