Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -154,13 +154,13 @@ def analyze_space_activity(available_spaces, repo_dir):
|
|
| 154 |
return space_activity
|
| 155 |
|
| 156 |
def create_status_display(space_activity):
|
| 157 |
-
"""Create formatted status display for all spaces"""
|
| 158 |
-
status_display = "π **Current Space Status (sorted by availability):**
|
| 159 |
|
| 160 |
for i, space in enumerate(space_activity, 1):
|
| 161 |
-
status_display += f"{i}. **{space['space_name']}**
|
| 162 |
-
status_display += f"
|
| 163 |
-
status_display += f"
|
| 164 |
|
| 165 |
return status_display
|
| 166 |
|
|
@@ -208,7 +208,7 @@ def select_space_with_boundary_check(space_activity, student_id):
|
|
| 208 |
return redirect_to_space(redirect_url, selected_space, status_display)
|
| 209 |
|
| 210 |
def redirect_to_space(redirect_url, selected_space, status_display):
|
| 211 |
-
"""
|
| 212 |
|
| 213 |
if selected_space['idle_minutes'] == float('inf'):
|
| 214 |
idle_info = "Never used (completely fresh)"
|
|
@@ -217,17 +217,17 @@ def redirect_to_space(redirect_url, selected_space, status_display):
|
|
| 217 |
|
| 218 |
redirect_html = f"""
|
| 219 |
<div style="max-width: 900px; margin: 0 auto; padding: 20px; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;">
|
| 220 |
-
<div style="text-align: center; margin-bottom: 30px; padding:
|
| 221 |
-
<h1 style="margin: 0 0
|
| 222 |
-
<h2 style="margin: 0; font-weight: normal;
|
| 223 |
-
<p style="margin:
|
| 224 |
β¨ This space was idle for: <strong>{idle_info}</strong>
|
| 225 |
</p>
|
| 226 |
</div>
|
| 227 |
|
| 228 |
-
<div style="background: #f8f9fa; padding: 25px; border-radius: 12px; margin-bottom: 25px; border-left: 4px solid #
|
| 229 |
<h3 style="margin-top: 0; color: #333;">π Space Selection Analysis</h3>
|
| 230 |
-
<div style="background: white; padding: 20px; border-radius: 8px; font-
|
| 231 |
{status_display}
|
| 232 |
</div>
|
| 233 |
<p style="margin-bottom: 0; color: #666; font-size: 14px; margin-top: 15px;">
|
|
@@ -235,46 +235,67 @@ def redirect_to_space(redirect_url, selected_space, status_display):
|
|
| 235 |
</p>
|
| 236 |
</div>
|
| 237 |
|
| 238 |
-
<div style="text-align: center; background: linear-gradient(135deg, #
|
| 239 |
-
<
|
| 240 |
-
<p style="
|
|
|
|
|
|
|
| 241 |
|
| 242 |
-
<
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
</
|
| 252 |
|
| 253 |
-
<
|
| 254 |
-
<
|
| 255 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
{redirect_url}
|
|
|
|
|
|
|
|
|
|
| 257 |
</p>
|
| 258 |
-
</
|
| 259 |
</div>
|
| 260 |
-
</div>
|
| 261 |
-
|
| 262 |
-
<script>
|
| 263 |
-
let countdown = 5;
|
| 264 |
-
const countdownElement = document.getElementById('countdown');
|
| 265 |
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 278 |
"""
|
| 279 |
|
| 280 |
return gr.HTML(redirect_html)
|
|
@@ -306,7 +327,7 @@ def get_url_params(request: gr.Request):
|
|
| 306 |
query_params = dict(request.query_params)
|
| 307 |
check_id = query_params.get('check', None)
|
| 308 |
if check_id:
|
| 309 |
-
return f"Load Distributor
|
| 310 |
else:
|
| 311 |
return "Load Distributor", None
|
| 312 |
return "Load Distributor", None
|
|
|
|
| 154 |
return space_activity
|
| 155 |
|
| 156 |
def create_status_display(space_activity):
|
| 157 |
+
"""Create formatted status display for all spaces with proper line breaks"""
|
| 158 |
+
status_display = "π **Current Space Status (sorted by availability):**<br><br>"
|
| 159 |
|
| 160 |
for i, space in enumerate(space_activity, 1):
|
| 161 |
+
status_display += f"{i}. **{space['space_name']}**<br>"
|
| 162 |
+
status_display += f" β’ Status: {space['status']}<br>"
|
| 163 |
+
status_display += f" β’ Last activity: {space['last_activity_str']}<br><br>"
|
| 164 |
|
| 165 |
return status_display
|
| 166 |
|
|
|
|
| 208 |
return redirect_to_space(redirect_url, selected_space, status_display)
|
| 209 |
|
| 210 |
def redirect_to_space(redirect_url, selected_space, status_display):
|
| 211 |
+
"""Display redirect information with manual click option (HF Spaces can't auto-redirect)"""
|
| 212 |
|
| 213 |
if selected_space['idle_minutes'] == float('inf'):
|
| 214 |
idle_info = "Never used (completely fresh)"
|
|
|
|
| 217 |
|
| 218 |
redirect_html = f"""
|
| 219 |
<div style="max-width: 900px; margin: 0 auto; padding: 20px; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;">
|
| 220 |
+
<div style="text-align: center; margin-bottom: 30px; padding: 25px; background: linear-gradient(135deg, #28a745, #20c997); color: white; border-radius: 12px; box-shadow: 0 4px 6px rgba(0,0,0,0.1);">
|
| 221 |
+
<h1 style="margin: 0 0 15px 0; font-size: 28px;">π― Learning Assistant Assigned</h1>
|
| 222 |
+
<h2 style="margin: 0 0 10px 0; font-weight: normal; font-size: 24px;">{selected_space['space_name']}</h2>
|
| 223 |
+
<p style="margin: 0; font-size: 18px; opacity: 0.9;">
|
| 224 |
β¨ This space was idle for: <strong>{idle_info}</strong>
|
| 225 |
</p>
|
| 226 |
</div>
|
| 227 |
|
| 228 |
+
<div style="background: #f8f9fa; padding: 25px; border-radius: 12px; margin-bottom: 25px; border-left: 4px solid #28a745;">
|
| 229 |
<h3 style="margin-top: 0; color: #333;">π Space Selection Analysis</h3>
|
| 230 |
+
<div style="background: white; padding: 20px; border-radius: 8px; font-size: 14px; line-height: 1.8; border: 1px solid #e9ecef;">
|
| 231 |
{status_display}
|
| 232 |
</div>
|
| 233 |
<p style="margin-bottom: 0; color: #666; font-size: 14px; margin-top: 15px;">
|
|
|
|
| 235 |
</p>
|
| 236 |
</div>
|
| 237 |
|
| 238 |
+
<div style="text-align: center; margin-bottom: 30px; padding: 25px; background: linear-gradient(135deg, #2196f3, #1976d2); color: white; border-radius: 12px; box-shadow: 0 4px 6px rgba(33,150,243,0.3);">
|
| 239 |
+
<h2 style="margin-top: 0; color: white;">π Access Your Learning Assistant</h2>
|
| 240 |
+
<p style="color: rgba(255,255,255,0.9); font-size: 16px; margin-bottom: 25px;">
|
| 241 |
+
Click the button below or copy the URL to access your assigned learning assistant.
|
| 242 |
+
</p>
|
| 243 |
|
| 244 |
+
<a href="{redirect_url}"
|
| 245 |
+
target="_blank"
|
| 246 |
+
style="display: inline-block; background: rgba(255,255,255,0.15); color: white;
|
| 247 |
+
padding: 15px 30px; font-size: 18px; font-weight: bold; text-decoration: none;
|
| 248 |
+
border-radius: 25px; border: 2px solid rgba(255,255,255,0.3);
|
| 249 |
+
transition: all 0.3s ease; margin-bottom: 20px;"
|
| 250 |
+
onmouseover="this.style.background='rgba(255,255,255,0.25)'; this.style.transform='translateY(-2px)'"
|
| 251 |
+
onmouseout="this.style.background='rgba(255,255,255,0.15)'; this.style.transform='translateY(0px)'">
|
| 252 |
+
Right-click β "Open in new tab"
|
| 253 |
+
</a>
|
| 254 |
|
| 255 |
+
<div style="background: rgba(0,0,0,0.1); padding: 15px; border-radius: 8px; margin-top: 15px;">
|
| 256 |
+
<p style="margin: 5px 0; color: rgba(255,255,255,0.9); font-size: 14px; font-weight: bold;">
|
| 257 |
+
π Copy this URL:
|
| 258 |
+
</p>
|
| 259 |
+
<div style="background: rgba(255,255,255,0.9); color: #333; padding: 12px; border-radius: 5px;
|
| 260 |
+
font-family: 'Courier New', monospace; font-size: 12px; word-break: break-all;
|
| 261 |
+
border: 1px solid rgba(255,255,255,0.5); margin-top: 8px;"
|
| 262 |
+
onclick="navigator.clipboard.writeText('{redirect_url}').then(() => {{
|
| 263 |
+
this.style.background='#d4edda';
|
| 264 |
+
this.innerHTML = 'β
URL Copied! Paste in new browser tab';
|
| 265 |
+
setTimeout(() => {{
|
| 266 |
+
this.style.background='rgba(255,255,255,0.9)';
|
| 267 |
+
this.innerHTML = '{redirect_url}';
|
| 268 |
+
}}, 2000);
|
| 269 |
+
}}).catch(() => {{
|
| 270 |
+
this.innerHTML = 'Click failed - please manually select and copy';
|
| 271 |
+
}})"
|
| 272 |
+
style="cursor: pointer; user-select: all;">
|
| 273 |
{redirect_url}
|
| 274 |
+
</div>
|
| 275 |
+
<p style="margin: 8px 0 0 0; color: rgba(255,255,255,0.8); font-size: 12px;">
|
| 276 |
+
π‘ Click the URL above to copy it automatically
|
| 277 |
</p>
|
| 278 |
+
</div>
|
| 279 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
|
| 281 |
+
<div style="background: #fff3cd; border: 1px solid #ffeaa7; border-radius: 8px; padding: 20px; margin-bottom: 20px;">
|
| 282 |
+
<h4 style="margin-top: 0; color: #856404;">π Alternative Access Methods</h4>
|
| 283 |
+
<div style="color: #856404; line-height: 1.6;">
|
| 284 |
+
<p><strong>Method 1:</strong> Click the blue button above (recommended)</p>
|
| 285 |
+
<p><strong>Method 2:</strong> Copy and paste this URL into a new browser tab:</p>
|
| 286 |
+
<div style="background: white; padding: 10px; border-radius: 5px; margin: 10px 0; font-family: monospace; font-size: 12px; word-break: break-all; border: 1px solid #ddd;">
|
| 287 |
+
{redirect_url}
|
| 288 |
+
</div>
|
| 289 |
+
<p><strong>Method 3:</strong> Search for "{selected_space['space_name']}" on Hugging Face Spaces</p>
|
| 290 |
+
</div>
|
| 291 |
+
</div>
|
| 292 |
+
|
| 293 |
+
<div style="text-align: center; padding: 20px; background: #f1f3f4; border-radius: 8px; margin-top: 20px;">
|
| 294 |
+
<p style="margin: 0; color: #5f6368; font-size: 14px;">
|
| 295 |
+
π Need a different assistant? <a href="javascript:location.reload()" style="color: #1976d2; text-decoration: none;">Refresh this page</a> to get reassigned.
|
| 296 |
+
</p>
|
| 297 |
+
</div>
|
| 298 |
+
</div>
|
| 299 |
"""
|
| 300 |
|
| 301 |
return gr.HTML(redirect_html)
|
|
|
|
| 327 |
query_params = dict(request.query_params)
|
| 328 |
check_id = query_params.get('check', None)
|
| 329 |
if check_id:
|
| 330 |
+
return f"Load Distributor", check_id
|
| 331 |
else:
|
| 332 |
return "Load Distributor", None
|
| 333 |
return "Load Distributor", None
|