linxinhua commited on
Commit
a8521d6
·
verified ·
1 Parent(s): 80381f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -155
app.py CHANGED
@@ -1,47 +1,18 @@
1
  import gradio as gr
2
  import os
3
  import csv
4
-
5
-
6
  from datetime import datetime, timedelta
7
  from huggingface_hub import Repository
8
  import threading
9
  import time
10
  import json
11
 
12
-
13
  # Configuration
14
  DATA_STORAGE_REPO = "CIV3283/Data_Storage"
15
-
16
-
17
-
18
-
19
-
20
-
21
  DATA_BRANCH_NAME = "data_branch"
22
  LOCAL_DATA_DIR = "temp_data_storage"
23
  MIN_IDLE_MINUTES = 10 # Minimum idle time required for space assignment
24
  ALLOCATION_LOCK_DURATION = 5 # Lock duration in minutes
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
 
46
  # 缓存配置 - 全部改为内存存储
47
  CACHE_UPDATE_INTERVAL = 600 # 10分钟 = 600秒
@@ -56,13 +27,7 @@ class MemoryAllocationStore:
56
  self._allocations = {} # {space_name: {'student_id': str, 'allocated_time': datetime, 'expires_at': datetime}}
57
  self._lock = threading.Lock()
58
  self._cleanup_interval = 60 # 每分钟清理一次过期记录
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
  # 启动后台清理线程
67
  self._start_cleanup_thread()
68
 
@@ -821,18 +786,6 @@ def select_space_with_enhanced_collision_avoidance_cached(space_activity, studen
821
  alternative_spaces = [s for s in basic_available_spaces[1:]
822
  if not local_tracker.is_recently_allocated_locally(s['space_name'])[0]]
823
 
824
-
825
-
826
-
827
-
828
-
829
-
830
-
831
-
832
-
833
-
834
-
835
-
836
  if alternative_spaces:
837
  selected_space = alternative_spaces[0]
838
  space_name = selected_space['space_name']
@@ -958,52 +911,11 @@ def create_status_display_with_cache_info(space_activity):
958
  status_display = "📊 **Current Space Status (sorted by availability):**<br><br>"
959
 
960
 
961
-
962
-
963
-
964
-
965
-
966
-
967
-
968
-
969
-
970
  # 显示缓存信息
971
  if cache_info:
972
  if cache_info['is_fresh']:
973
  cache_status = f"✅ Fresh (updated {cache_info['age_minutes']:.1f} min ago)"
974
 
975
-
976
-
977
-
978
-
979
-
980
-
981
-
982
-
983
-
984
-
985
-
986
-
987
-
988
-
989
-
990
-
991
-
992
-
993
-
994
-
995
-
996
-
997
-
998
-
999
-
1000
-
1001
-
1002
-
1003
-
1004
-
1005
-
1006
-
1007
  else:
1008
  cache_status = f"⚠️ Stale (updated {cache_info['age_minutes']:.1f} min ago)"
1009
 
@@ -1244,70 +1156,6 @@ def create_admin_interface():
1244
  result = clear_memory_allocations()
1245
  if 'error' in result:
1246
  return result, "❌ Failed to clear memory allocations"
1247
-
1248
-
1249
-
1250
-
1251
-
1252
-
1253
-
1254
-
1255
-
1256
-
1257
-
1258
-
1259
-
1260
-
1261
-
1262
-
1263
-
1264
-
1265
-
1266
-
1267
-
1268
-
1269
-
1270
-
1271
-
1272
-
1273
-
1274
-
1275
-
1276
-
1277
-
1278
-
1279
-
1280
-
1281
-
1282
-
1283
-
1284
-
1285
-
1286
-
1287
-
1288
-
1289
-
1290
-
1291
-
1292
-
1293
-
1294
-
1295
-
1296
-
1297
-
1298
-
1299
-
1300
-
1301
-
1302
-
1303
-
1304
-
1305
-
1306
-
1307
-
1308
-
1309
-
1310
-
1311
  else:
1312
  # 获取更新后的状态
1313
  status = get_memory_allocation_status()
@@ -1324,8 +1172,6 @@ def create_admin_interface():
1324
  force_cache_update_btn.click(
1325
  fn=force_update,
1326
  outputs=[cache_info_display, cache_status_message]
1327
-
1328
-
1329
  )
1330
 
1331
  # Data tab event handlers
 
1
  import gradio as gr
2
  import os
3
  import csv
 
 
4
  from datetime import datetime, timedelta
5
  from huggingface_hub import Repository
6
  import threading
7
  import time
8
  import json
9
 
 
10
  # Configuration
11
  DATA_STORAGE_REPO = "CIV3283/Data_Storage"
 
 
 
 
 
 
12
  DATA_BRANCH_NAME = "data_branch"
13
  LOCAL_DATA_DIR = "temp_data_storage"
14
  MIN_IDLE_MINUTES = 10 # Minimum idle time required for space assignment
15
  ALLOCATION_LOCK_DURATION = 5 # Lock duration in minutes
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  # 缓存配置 - 全部改为内存存储
18
  CACHE_UPDATE_INTERVAL = 600 # 10分钟 = 600秒
 
27
  self._allocations = {} # {space_name: {'student_id': str, 'allocated_time': datetime, 'expires_at': datetime}}
28
  self._lock = threading.Lock()
29
  self._cleanup_interval = 60 # 每分钟清理一次过期记录
30
+
 
 
 
 
 
 
31
  # 启动后台清理线程
32
  self._start_cleanup_thread()
33
 
 
786
  alternative_spaces = [s for s in basic_available_spaces[1:]
787
  if not local_tracker.is_recently_allocated_locally(s['space_name'])[0]]
788
 
 
 
 
 
 
 
 
 
 
 
 
 
789
  if alternative_spaces:
790
  selected_space = alternative_spaces[0]
791
  space_name = selected_space['space_name']
 
911
  status_display = "📊 **Current Space Status (sorted by availability):**<br><br>"
912
 
913
 
 
 
 
 
 
 
 
 
 
914
  # 显示缓存信息
915
  if cache_info:
916
  if cache_info['is_fresh']:
917
  cache_status = f"✅ Fresh (updated {cache_info['age_minutes']:.1f} min ago)"
918
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
919
  else:
920
  cache_status = f"⚠️ Stale (updated {cache_info['age_minutes']:.1f} min ago)"
921
 
 
1156
  result = clear_memory_allocations()
1157
  if 'error' in result:
1158
  return result, "❌ Failed to clear memory allocations"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1159
  else:
1160
  # 获取更新后的状态
1161
  status = get_memory_allocation_status()
 
1172
  force_cache_update_btn.click(
1173
  fn=force_update,
1174
  outputs=[cache_info_display, cache_status_message]
 
 
1175
  )
1176
 
1177
  # Data tab event handlers