llamameta commited on
Commit
e2ac114
1 Parent(s): 4a63e64

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +89 -19
index.html CHANGED
@@ -1,19 +1,89 @@
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
+ <!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>Black Forest Labs - Load Balanced Streamlit</title>
7
+ <style>
8
+ html, body {
9
+ margin: 0;
10
+ padding: 0;
11
+ width: 100%;
12
+ height: 100%;
13
+ }
14
+ #loading {
15
+ position: fixed;
16
+ top: 0;
17
+ left: 0;
18
+ width: 100%;
19
+ height: 100%;
20
+ background: rgba(255, 255, 255, 0.8);
21
+ display: flex;
22
+ justify-content: center;
23
+ align-items: center;
24
+ font-size: 24px;
25
+ z-index: 1000;
26
+ }
27
+ iframe {
28
+ width: 100%;
29
+ height: 100vh;
30
+ border: none;
31
+ }
32
+ </style>
33
+ </head>
34
+ <body>
35
+ <div id="loading">Please wait Memilih server optimal...</div>
36
+ <iframe id="streamlit-frame"></iframe>
37
+
38
+ <script>
39
+ const SERVERS = [
40
+ "https://geminisearch-fu8l82trhp7dadkyncasdm.streamlit.app/?embed=true",
41
+ "https://geminisearch-fu8l82trhp7dadkyncasdm.streamlit.app/?embed=true"
42
+ ];
43
+
44
+ // Fungsi untuk mengecek kecepatan respons server
45
+ async function checkServerSpeed(url) {
46
+ const start = performance.now();
47
+ try {
48
+ const response = await fetch(url, { method: 'HEAD', mode: 'no-cors' });
49
+ const end = performance.now();
50
+ return end - start;
51
+ } catch (error) {
52
+ console.error(`Error checking ${url}:`, error);
53
+ return Infinity;
54
+ }
55
+ }
56
+
57
+ // Fungsi untuk memilih server berdasarkan kecepatan respons
58
+ async function chooseServer() {
59
+ const speeds = await Promise.all(SERVERS.map(checkServerSpeed));
60
+ const fastestIndex = speeds.indexOf(Math.min(...speeds));
61
+ return SERVERS[fastestIndex];
62
+ }
63
+
64
+ // Fungsi untuk memuat Streamlit
65
+ async function loadStreamlit() {
66
+ const loadingElement = document.getElementById('loading');
67
+ const iframe = document.getElementById('streamlit-frame');
68
+
69
+ // Cek apakah sudah ada URL yang tersimpan di sessionStorage
70
+ let chosenUrl = sessionStorage.getItem('streamlitUrl');
71
+
72
+ if (!chosenUrl) {
73
+ // Jika belum ada, pilih server dan simpan ke sessionStorage
74
+ chosenUrl = await chooseServer();
75
+ sessionStorage.setItem('streamlitUrl', chosenUrl);
76
+ }
77
+
78
+ // Tampilkan iframe dan sembunyikan loading
79
+ iframe.src = chosenUrl;
80
+ iframe.onload = () => {
81
+ loadingElement.style.display = 'none';
82
+ };
83
+ }
84
+
85
+ // Jalankan loadStreamlit saat halaman dimuat
86
+ window.onload = loadStreamlit;
87
+ </script>
88
+ </body>
89
+ </html>