BriranSus commited on
Commit
99bb05a
·
1 Parent(s): 6c01e44

feat: add animations

Browse files
Files changed (1) hide show
  1. app.py +39 -12
app.py CHANGED
@@ -207,7 +207,7 @@ def format_loading_html():
207
 
208
  def format_result_html(caption):
209
  return f"""
210
- <div style="
211
  text-align: center;
212
  padding: 30px;
213
  border: 2px solid #4F46E5;
@@ -282,12 +282,10 @@ def predict(image):
282
  js_head = """
283
  <script>
284
  function showToast(message, type) {
285
- // Create Toast Element
286
  const toast = document.createElement("div");
287
  toast.className = "toast";
288
  toast.innerText = message;
289
 
290
- // Color Logic
291
  if (type === 'error') {
292
  toast.style.backgroundColor = "#EF4444"; // Red
293
  toast.style.color = "#FFFFFF";
@@ -298,10 +296,8 @@ function showToast(message, type) {
298
 
299
  document.body.appendChild(toast);
300
 
301
- // Remove after animation/timeout
302
  setTimeout(() => {
303
  toast.classList.add('hiding');
304
- // Wait for fadeOut animation to finish before removing
305
  toast.addEventListener('animationend', () => toast.remove());
306
  }, 2500);
307
  }
@@ -323,7 +319,6 @@ function copyToClipboard(text) {
323
  function openModal() {
324
  const modal = document.getElementById("custom-api-modal");
325
  modal.classList.remove("hidden");
326
- // Force a reflow if needed, but usually removing hidden is enough
327
  }
328
 
329
  function closeModal() {
@@ -341,7 +336,17 @@ document.addEventListener("click", function(e) {
341
 
342
  custom_css = """
343
  body { background-color: #111827; }
344
- .container { max-width: 800px; margin: auto; padding-top: 20px; }
 
 
 
 
 
 
 
 
 
 
345
  .header { text-align: center; margin-bottom: 30px; }
346
  .header h1 { color: #818CF8; font-size: 2.5rem; }
347
  .header p { color: #9CA3AF; }
@@ -352,6 +357,27 @@ body { background-color: #111827; }
352
  }
353
  .loading-box { animation: pulse 1.5s cubic-bezier(0.4, 0, 0.6, 1) infinite; }
354
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
355
  @keyframes slideUpFadeIn {
356
  from { opacity: 0; transform: translate(-50%, 100%); }
357
  to { opacity: 1; transform: translate(-50%, 0); }
@@ -366,7 +392,7 @@ body { background-color: #111827; }
366
  position: fixed;
367
  bottom: 30px;
368
  left: 50%;
369
- transform: translate(-50%, 0); /* Center horizontally */
370
  padding: 12px 24px;
371
  border-radius: 8px;
372
  z-index: 10000;
@@ -388,10 +414,9 @@ body { background-color: #111827; }
388
  background-color: rgba(0,0,0,0.8);
389
  z-index: 9999;
390
  backdrop-filter: blur(5px);
391
- display: flex; /* Centering */
392
  justify-content: center;
393
  align-items: center;
394
-
395
  transition: opacity 0.2s ease-in-out;
396
  }
397
 
@@ -411,6 +436,7 @@ body { background-color: #111827; }
411
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
412
  color: #F3F4F6;
413
  position: relative;
 
414
  }
415
 
416
  /* Styled HTML Buttons to look like Gradio */
@@ -420,8 +446,9 @@ body { background-color: #111827; }
420
  font-weight: 600;
421
  cursor: pointer;
422
  border: none;
423
- transition: background-color 0.2s;
424
  }
 
425
 
426
  .btn-close {
427
  background: transparent;
@@ -434,7 +461,7 @@ body { background-color: #111827; }
434
  .btn-close:hover { color: #F3F4F6; }
435
 
436
  .btn-primary {
437
- background-color: #F97316; /* Gradio Orange-ish */
438
  color: white;
439
  width: 100%;
440
  margin-top: 20px;
 
207
 
208
  def format_result_html(caption):
209
  return f"""
210
+ <div class="result-animation" style="
211
  text-align: center;
212
  padding: 30px;
213
  border: 2px solid #4F46E5;
 
282
  js_head = """
283
  <script>
284
  function showToast(message, type) {
 
285
  const toast = document.createElement("div");
286
  toast.className = "toast";
287
  toast.innerText = message;
288
 
 
289
  if (type === 'error') {
290
  toast.style.backgroundColor = "#EF4444"; // Red
291
  toast.style.color = "#FFFFFF";
 
296
 
297
  document.body.appendChild(toast);
298
 
 
299
  setTimeout(() => {
300
  toast.classList.add('hiding');
 
301
  toast.addEventListener('animationend', () => toast.remove());
302
  }, 2500);
303
  }
 
319
  function openModal() {
320
  const modal = document.getElementById("custom-api-modal");
321
  modal.classList.remove("hidden");
 
322
  }
323
 
324
  function closeModal() {
 
336
 
337
  custom_css = """
338
  body { background-color: #111827; }
339
+ @keyframes fadeInUp {
340
+ from { opacity: 0; transform: translateY(20px); }
341
+ to { opacity: 1; transform: translateY(0); }
342
+ }
343
+
344
+ .container {
345
+ max-width: 800px;
346
+ margin: auto;
347
+ padding-top: 20px;
348
+ }
349
+
350
  .header { text-align: center; margin-bottom: 30px; }
351
  .header h1 { color: #818CF8; font-size: 2.5rem; }
352
  .header p { color: #9CA3AF; }
 
357
  }
358
  .loading-box { animation: pulse 1.5s cubic-bezier(0.4, 0, 0.6, 1) infinite; }
359
 
360
+ button {
361
+ transition: all 0.2s ease-in-out !important;
362
+ }
363
+ button:hover {
364
+ transform: translateY(-2px);
365
+ box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
366
+ }
367
+ button:active {
368
+ transform: translateY(0);
369
+ }
370
+
371
+ @keyframes popIn {
372
+ 0% { opacity: 0; transform: scale(0.9); }
373
+ 70% { transform: scale(1.02); }
374
+ 100% { opacity: 1; transform: scale(1); }
375
+ }
376
+
377
+ .result-animation {
378
+ animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
379
+ }
380
+
381
  @keyframes slideUpFadeIn {
382
  from { opacity: 0; transform: translate(-50%, 100%); }
383
  to { opacity: 1; transform: translate(-50%, 0); }
 
392
  position: fixed;
393
  bottom: 30px;
394
  left: 50%;
395
+ transform: translate(-50%, 0);
396
  padding: 12px 24px;
397
  border-radius: 8px;
398
  z-index: 10000;
 
414
  background-color: rgba(0,0,0,0.8);
415
  z-index: 9999;
416
  backdrop-filter: blur(5px);
417
+ display: flex;
418
  justify-content: center;
419
  align-items: center;
 
420
  transition: opacity 0.2s ease-in-out;
421
  }
422
 
 
436
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
437
  color: #F3F4F6;
438
  position: relative;
439
+ animation: popIn 0.3s ease-out forwards;
440
  }
441
 
442
  /* Styled HTML Buttons to look like Gradio */
 
446
  font-weight: 600;
447
  cursor: pointer;
448
  border: none;
449
+ transition: background-color 0.2s, transform 0.1s;
450
  }
451
+ .cutom-btn:active { transform: scale(0.95); }
452
 
453
  .btn-close {
454
  background: transparent;
 
461
  .btn-close:hover { color: #F3F4F6; }
462
 
463
  .btn-primary {
464
+ background-color: #F97316;
465
  color: white;
466
  width: 100%;
467
  margin-top: 20px;