Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -86,9 +86,20 @@ def refresh_models():
|
|
86 |
all_models = get_all_models(FREE_MODEL_TEST_KEY)
|
87 |
|
88 |
free_models = []
|
89 |
-
|
90 |
-
|
91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
|
93 |
logging.info(f"所有模型列表:{all_models}")
|
94 |
logging.info(f"免费模型列表:{free_models}")
|
|
|
86 |
all_models = get_all_models(FREE_MODEL_TEST_KEY)
|
87 |
|
88 |
free_models = []
|
89 |
+
|
90 |
+
# 使用 ThreadPoolExecutor 并发执行测试
|
91 |
+
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor: # 限制最大工作线程数为 10,可根据实际情况调整
|
92 |
+
# 创建一个模型到 future 的映射
|
93 |
+
future_to_model = {executor.submit(test_model_availability, FREE_MODEL_TEST_KEY, model): model for model in all_models}
|
94 |
+
|
95 |
+
for future in concurrent.futures.as_completed(future_to_model):
|
96 |
+
model = future_to_model[future]
|
97 |
+
try:
|
98 |
+
is_free = future.result()
|
99 |
+
if is_free:
|
100 |
+
free_models.append(model)
|
101 |
+
except Exception as exc:
|
102 |
+
logging.error(f"模型 {model} 测试生成异常: {exc}")
|
103 |
|
104 |
logging.info(f"所有模型列表:{all_models}")
|
105 |
logging.info(f"免费模型列表:{free_models}")
|