Yang2001 commited on
Commit
889199c
·
1 Parent(s): 8eff1b6

update app.py

Browse files
Files changed (1) hide show
  1. app.py +95 -20
app.py CHANGED
@@ -19,6 +19,17 @@ import gradio as gr
19
  REMOTE_URL = os.environ.get("REMOTE_URL", "")
20
  GPU_NAME = os.environ.get("GPU_NAME", "")
21
 
 
 
 
 
 
 
 
 
 
 
 
22
  PROXY_HTML = """
23
  <!DOCTYPE html>
24
  <html lang="en">
@@ -122,6 +133,65 @@ PROXY_HTML = """
122
  border-radius: 4px;
123
  font-size: 13px;
124
  }}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  .link-bar {{
126
  padding: 8px 24px;
127
  background: rgba(16, 185, 129, 0.08);
@@ -153,31 +223,36 @@ PROXY_HTML = """
153
 
154
 
155
  def build_page():
156
- if REMOTE_URL:
 
157
  status_color = "#10b981"
158
  status_anim = "pulse 2s infinite"
159
- status_text = "Connected to remote GPU instance"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  content = f"""
161
- <div class="no-url">
162
- <div class="no-url-card">
163
- <h2>🚀 Redirecting to Pixal3D...</h2>
164
- <p style="color:#fbbf24; margin-bottom:12px;">⚠️ Due to a temporary HuggingFace error, this Space is currently unavailable. We have prepared a temporary locally-deployed instance for you.</p>
165
- <p style="color:#f59e0b; margin-bottom:12px;"> All users share a single GPU requests are queued. Please be patient.</p>
166
- <p>You will be redirected automatically.</p>
167
- <p style="margin-top:16px;">
168
- <a href="{REMOTE_URL}" target="_blank" rel="noopener noreferrer" style="display:inline-block; padding:12px 32px; background:linear-gradient(135deg,#818cf8,#10b981); color:#fff; border-radius:8px; text-decoration:none; font-weight:600; font-size:15px;">
169
- Click here if not redirected
170
- </a>
171
- </p>
172
- <p style="margin-top:16px; font-size:12px; color:#64748b;">Target: <code>{REMOTE_URL}</code></p>
173
  </div>
174
  </div>
175
- <script>
176
- // Auto redirect in new tab after a short delay
177
- setTimeout(function() {{
178
- window.open("{REMOTE_URL}", "_blank");
179
- }}, 1500);
180
- </script>
181
  """
182
  else:
183
  status_color = "#ef4444"
 
19
  REMOTE_URL = os.environ.get("REMOTE_URL", "")
20
  GPU_NAME = os.environ.get("GPU_NAME", "")
21
 
22
+ # Multi-instance support: REMOTE_URL as #0, REMOTE_URL_1, REMOTE_URL_2, REMOTE_URL_3
23
+ REMOTE_URLS = []
24
+ if REMOTE_URL:
25
+ name0 = os.environ.get("REMOTE_NAME", "Instance 0")
26
+ REMOTE_URLS.append({"url": REMOTE_URL, "name": name0})
27
+ for i in range(1, 4):
28
+ url = os.environ.get(f"REMOTE_URL_{i}", "")
29
+ name = os.environ.get(f"REMOTE_NAME_{i}", f"Instance {i}")
30
+ if url:
31
+ REMOTE_URLS.append({"url": url, "name": name})
32
+
33
  PROXY_HTML = """
34
  <!DOCTYPE html>
35
  <html lang="en">
 
133
  border-radius: 4px;
134
  font-size: 13px;
135
  }}
136
+ .cards-container {{
137
+ flex: 1;
138
+ display: flex;
139
+ flex-direction: column;
140
+ align-items: center;
141
+ justify-content: center;
142
+ padding: 40px;
143
+ overflow-y: auto;
144
+ }}
145
+ .cards-grid {{
146
+ display: grid;
147
+ grid-template-columns: repeat(2, 1fr);
148
+ gap: 28px;
149
+ max-width: 1000px;
150
+ width: 100%;
151
+ }}
152
+ .instance-card {{
153
+ width: 100%;
154
+ background: rgba(22, 28, 45, 0.8);
155
+ border: 1px solid rgba(255,255,255,0.08);
156
+ border-radius: 24px;
157
+ padding: 60px 48px;
158
+ text-align: center;
159
+ transition: transform 0.2s, border-color 0.2s;
160
+ }}
161
+ .instance-card:hover {{
162
+ transform: translateY(-4px);
163
+ border-color: rgba(129, 140, 248, 0.4);
164
+ }}
165
+ .instance-card h3 {{
166
+ font-size: 26px;
167
+ margin-bottom: 16px;
168
+ color: #f1f5f9;
169
+ }}
170
+ .instance-card .url-hint {{
171
+ font-size: 13px;
172
+ color: #64748b;
173
+ margin-top: 18px;
174
+ word-break: break-all;
175
+ }}
176
+ .instance-card .btn-go {{
177
+ display: inline-block;
178
+ margin-top: 24px;
179
+ padding: 16px 44px;
180
+ background: linear-gradient(135deg, #818cf8, #10b981);
181
+ color: #ffffff !important;
182
+ border-radius: 12px;
183
+ text-decoration: none !important;
184
+ font-weight: 700;
185
+ font-size: 18px;
186
+ transition: opacity 0.2s;
187
+ }}
188
+ .instance-card .btn-go:hover {{
189
+ opacity: 0.85;
190
+ text-decoration: none !important;
191
+ }}
192
+ .instance-card .btn-go:hover {{
193
+ opacity: 0.85;
194
+ }}
195
  .link-bar {{
196
  padding: 8px 24px;
197
  background: rgba(16, 185, 129, 0.08);
 
223
 
224
 
225
  def build_page():
226
+ # If multi-instance URLs are configured, show cards
227
+ if REMOTE_URLS:
228
  status_color = "#10b981"
229
  status_anim = "pulse 2s infinite"
230
+ status_text = f"{len(REMOTE_URLS)} instance(s) available"
231
+
232
+ cards_html = ""
233
+ for i, inst in enumerate(REMOTE_URLS):
234
+ cards_html += f"""
235
+ <div class="instance-card">
236
+ <h3>🖥️ {inst['name']}</h3>
237
+ <p style="color:#94a3b8; font-size:14px; margin-bottom:8px;">⚡ Shared GPU — requests are queued</p>
238
+ <a href="{inst['url']}" target="_blank" rel="noopener noreferrer" class="btn-go">
239
+ Open Instance {i+1}
240
+ </a>
241
+ <p class="url-hint"><code>{inst['url']}</code></p>
242
+ </div>
243
+ """
244
+
245
  content = f"""
246
+ <div class="cards-container">
247
+ <div style="width:100%; text-align:center; margin-bottom:16px;">
248
+ <h2 style="font-size:28px; margin-bottom:12px;">🚀 Choose a Pixal3D Instance</h2>
249
+ <p style="color:#fbbf24; font-size:15px; margin-bottom:8px;">⚠️ Due to a temporary HuggingFace error, this Space is currently unavailable. Please use one of the instances below.</p>
250
+ <p style="color:#10b981; font-size:14px; margin-top:10px; font-weight:600;">💡 After entering, check the top-left corner for the current queue count.</p>
251
+ </div>
252
+ <div class="cards-grid">
253
+ {cards_html}
 
 
 
 
254
  </div>
255
  </div>
 
 
 
 
 
 
256
  """
257
  else:
258
  status_color = "#ef4444"