Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3975a3370a | ||
|
|
7313f8da67 |
41
main.py
41
main.py
@@ -123,20 +123,22 @@ def init_db():
|
|||||||
|
|
||||||
def search_models(keyword: str, limit: int = 100) -> list:
|
def search_models(keyword: str, limit: int = 100) -> list:
|
||||||
"""从 ModelScope 搜索模型"""
|
"""从 ModelScope 搜索模型"""
|
||||||
url = f"{MODELSCOPE_API}/models"
|
url = "https://modelscope.cn/openapi/v1/models"
|
||||||
params = {
|
params = {
|
||||||
'Query': keyword,
|
'search': keyword,
|
||||||
'PageSize': limit,
|
'page_size': limit,
|
||||||
'SortBy': 'GITHUB_SCORE',
|
'page_number': 1,
|
||||||
|
'sort': 'downloads',
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
resp = requests.get(url, params=params, timeout=15)
|
resp = requests.get(url, params=params, timeout=20,
|
||||||
|
headers={'User-Agent': 'Mozilla/5.0'})
|
||||||
data = resp.json()
|
data = resp.json()
|
||||||
models = data.get('Data', {}).get('Models', [])
|
if data.get('success'):
|
||||||
return models
|
return data.get('data', {}).get('models', [])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log(f" 搜索失败 [{keyword}]: {e}")
|
log(f" 搜索失败 [{keyword}]: {e}")
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
def check_architecture(model_id: str) -> tuple:
|
def check_architecture(model_id: str) -> tuple:
|
||||||
@@ -367,16 +369,16 @@ def run_pipeline(gpus: list = None, submit_limit: int = 30):
|
|||||||
for kw in SEARCH_KEYWORDS:
|
for kw in SEARCH_KEYWORDS:
|
||||||
models = search_models(kw, limit=100)
|
models = search_models(kw, limit=100)
|
||||||
for m in models:
|
for m in models:
|
||||||
mid = m.get('ModelId', m.get('Name', ''))
|
mid = m.get('id', '')
|
||||||
if mid and mid not in seen:
|
if mid and mid not in seen:
|
||||||
seen.add(mid)
|
seen.add(mid)
|
||||||
downloads = m.get('Downloads', 0)
|
downloads = m.get('downloads', 0)
|
||||||
if downloads >= 50:
|
if downloads >= 50:
|
||||||
all_models.append({
|
all_models.append({
|
||||||
'model_id': mid,
|
'model_id': mid,
|
||||||
'url': f"https://modelscope.cn/{mid}",
|
'url': f"https://modelscope.cn/{mid}",
|
||||||
'downloads': downloads,
|
'downloads': downloads,
|
||||||
'params': m.get('Parameters', ''),
|
'params': m.get('params', ''),
|
||||||
'category': 'quantized' if 'GGUF' in mid.upper() else 'standard',
|
'category': 'quantized' if 'GGUF' in mid.upper() else 'standard',
|
||||||
})
|
})
|
||||||
time.sleep(0.3)
|
time.sleep(0.3)
|
||||||
@@ -570,6 +572,23 @@ def main():
|
|||||||
log(f"STRATEGY_ID: {STRATEGY_ID}")
|
log(f"STRATEGY_ID: {STRATEGY_ID}")
|
||||||
log(f"GPU: {', '.join(GPU_CONFIGS.keys())}")
|
log(f"GPU: {', '.join(GPU_CONFIGS.keys())}")
|
||||||
|
|
||||||
|
# 启动后自动执行一次提交流程
|
||||||
|
def _auto_run():
|
||||||
|
time.sleep(3) # 等 HTTP 服务就绪
|
||||||
|
log("自动触发提交流程...")
|
||||||
|
try:
|
||||||
|
state['running'] = True
|
||||||
|
state['last_run'] = datetime.now().isoformat()
|
||||||
|
count = run_pipeline(submit_limit=30)
|
||||||
|
state['last_result'] = {'submitted': count, 'success': True}
|
||||||
|
except Exception as e:
|
||||||
|
log(f"流程异常: {traceback.format_exc()}")
|
||||||
|
state['last_result'] = {'error': str(e), 'success': False}
|
||||||
|
finally:
|
||||||
|
state['running'] = False
|
||||||
|
|
||||||
|
threading.Thread(target=_auto_run, daemon=True).start()
|
||||||
|
|
||||||
while not shutdown_requested:
|
while not shutdown_requested:
|
||||||
server.handle_request()
|
server.handle_request()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user