Commit f2698399 authored by wangkx1's avatar wangkx1
Browse files

update new-moon

parent c0705977
应用要求:
一、UI描述,支持白天和夜晚2种UI
1 UI
网页左侧布置3个按钮,分别是
配置、下载、管理
二、功能:
主要功能:
1、配置本地路径
2、下载模型;
3、模型管理;
3.1 删除模型
3.2 上传模型
4、模型的下载、上传、删除,需要并发进行,不能互相干扰(除非同一个模型被同时操作);
具体功能呢
1、配置路径
本地地址配置页面,可以配置本地要管理的目录;
我希望配置的内容在本地使用yaml文件存储的;
未配置之前,按钮是灰色的,配好之后按钮是绿色的;
下载模型、模型管理、上传模型执行之前,检查是否配置好了路径,如果没有则禁止执行任务;
2、下载模型
模型一旦开始下载,无论单个还是批量;
(1)每次仅仅同时下载一个模型,下载失败后,反复再次尝试下载10次;
(2)预估modelscope远程模型的总大小; (可能会失败,建议先完成单元测试,获取大小失败卡住不要卡住)
(3)支持删除任务、暂停任务;设置优先下载后,自动上升到顶部。
(4)根据文件数量显示下载进度;
(5)下载顺序默认按照发起下载任务的时间顺序,从上到下排序;支持选中某一个任务让它置顶,优先下载;
(6)支持下载任务暂停,如果当前任务暂停后,则继续下载排队的任务;
3、模型管理
模型上传:模型需要上传到csghub,显示模型上传的进度、根据文件数量;已经上传的模型,自动变灰,到页面底部;
删除模型:支持选择已经下载完成的模型进行删除;
已知可能出现的BUG:
(1)浏览器输入地址后,打开需要比较快;
(2)当前在不同的浏览器打开后,模型下载的状态不是一致的,有的打开不会显示正在下载的模型;
\ No newline at end of file
#!/bin/bash
# 安装依赖
pip3 install -r requirements.txt
# 启动服务
python3 model_download_manager.py
docker pull 10.17.27.227/dev/man-model:v2.0
# 更改 -v 为你想要存储的目录
docker run -d --name model_download_manager \
-v /data/DataStore/models:/data/DataStore/models \
-p 7865:7865 -w /workspace/new-moon -e PYTHONUNBUFFERED=1 \
--restart unless-stopped 10.17.27.227/dev/man-model:v2.0 \
bash -c "python3 model_download_manager.py"
\ No newline at end of file
#!/usr/bin/env python3
"""
测试暂停功能的脚本
"""
import sys
import os
import time
import requests
# 添加当前目录到Python路径
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
# 导入模块
try:
from model_download_manager import create_download_task, pause_download, get_downloads_data, global_state
except ImportError as e:
print(f"导入失败: {e}")
sys.exit(1)
def test_pause_functionality():
print("=== 测试暂停下载功能 ===")
# 测试模型ID
test_model = "Qwen/Qwen2.5-1.5B-Instruct"
print(f"1. 创建下载任务: {test_model}")
task_id = create_download_task(test_model)
print(f" 任务ID: {task_id}")
# 等待任务开始下载
print("2. 等待任务开始下载...")
for i in range(10):
time.sleep(1)
with global_state.operation_lock:
task = global_state.state["download_tasks"].get(task_id)
if task and task.get("status") == "downloading":
print(f" 任务已开始下载: {task['status']}")
break
else:
print(" 任务未能开始下载,可能队列中还有其他任务")
return False
# 暂停任务
print(f"3. 暂停任务: {task_id}")
result = pause_download(task_id)
print(f" 暂停结果: {result}")
# 检查任务状态
print("4. 检查任务状态...")
time.sleep(2)
with global_state.operation_lock:
task = global_state.state["download_tasks"].get(task_id)
status = task.get("status") if task else "未知"
print(f" 任务状态: {status}")
# 检查是否有下载进程在运行
process_running = task_id in global_state.download_processes
print(f" 下载进程是否在运行: {'是' if process_running else '否'}")
if status == "paused" and not process_running:
print("5. 测试成功: 任务已暂停,下载进程已终止")
return True
else:
print("5. 测试失败: 任务未正确暂停或进程仍在运行")
return False
if __name__ == "__main__":
success = test_pause_functionality()
sys.exit(0 if success else 1)
\ No newline at end of file
#!/usr/bin/env python3
"""
高级测试暂停功能的脚本:
1. 创建多个下载任务
2. 暂停当前任务
3. 验证下一个任务自动开始
"""
import sys
import os
import time
import threading
import requests
# 添加当前目录到Python路径
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
# 导入模块
try:
from model_download_manager import (
create_download_task,
pause_download,
get_downloads_data,
global_state,
download_worker,
start_workers
)
import threading
except ImportError as e:
print(f"导入失败: {e}")
sys.exit(1)
def print_task_status():
"""打印所有下载任务的状态"""
with global_state.operation_lock:
print("当前任务状态:")
for task_id, task in global_state.state["download_tasks"].items():
print(f" 任务 {task_id}: {task['status']} - {task['model_id']} - {task['message']}")
print(f"活动下载: {list(global_state.active_downloads.keys())}")
print(f"下载进程: {list(global_state.download_processes.keys())}")
print("-" * 50)
def test_pause_with_next_task():
print("=== 高级测试:暂停并自动开始下一个任务 ===")
# 清除现有任务
with global_state.operation_lock:
global_state.state["download_tasks"].clear()
global_state.active_downloads.clear()
global_state.download_processes.clear()
global_state.download_queue.queue.clear()
# 确保工作线程在运行
if not hasattr(global_state, '_workers_started'):
start_workers()
global_state._workers_started = True
# 创建多个下载任务
test_models = [
"Qwen/Qwen2.5-1.5B-Instruct",
"Qwen/Qwen2.5-0.5B-Instruct",
"Qwen/Qwen2.5-0.5B-Chat"
]
print(f"1. 创建 {len(test_models)} 个下载任务")
task_ids = []
for i, model in enumerate(test_models):
task_id = create_download_task(model)
task_ids.append(task_id)
print(f" 任务 {i+1}: {task_id} - {model}")
print_task_status()
# 等待第一个任务开始下载
print("2. 等待第一个任务开始下载...")
first_task_id = task_ids[0]
for i in range(15):
time.sleep(1)
print_task_status()
with global_state.operation_lock:
task = global_state.state["download_tasks"].get(first_task_id)
if task and task.get("status") == "downloading":
print(f" 第一个任务 {first_task_id} 已开始下载")
break
print(f" 等待 {i+1}/15 秒...")
else:
print(" 第一个任务未能开始下载,测试失败")
return False
# 暂停第一个任务
print(f"3. 暂停第一个任务: {first_task_id}")
result = pause_download(first_task_id)
print(f" 暂停结果: {result}")
print_task_status()
# 等待下一个任务开始下载
print("4. 等待下一个任务自动开始...")
for i in range(15):
time.sleep(1)
print_task_status()
# 检查是否有任务在下载
with global_state.operation_lock:
downloading_tasks = [
task_id for task_id, task in global_state.state["download_tasks"].items()
if task.get("status") == "downloading"
]
if downloading_tasks and downloading_tasks[0] != first_task_id:
print(f" 下一个任务 {downloading_tasks[0]} 已自动开始下载")
break
print(f" 等待 {i+1}/15 秒...")
else:
print(" 下一个任务未能自动开始,测试失败")
return False
# 检查第一个任务是否已暂停
with global_state.operation_lock:
first_task = global_state.state["download_tasks"].get(first_task_id)
if first_task.get("status") != "paused":
print(" 第一个任务未正确暂停,测试失败")
return False
# 检查是否有其他任务在下载
downloading_tasks = [
task_id for task_id, task in global_state.state["download_tasks"].items()
if task.get("status") == "downloading"
]
if not downloading_tasks or downloading_tasks[0] == first_task_id:
print(" 没有其他任务在下载,测试失败")
return False
print("5. 测试成功:暂停功能正常,下一个任务自动开始")
print_task_status()
# 清理测试任务
print("6. 清理测试任务...")
with global_state.operation_lock:
for task_id in task_ids:
if task_id in global_state.state["download_tasks"]:
# 终止可能正在运行的进程
if task_id in global_state.download_processes:
try:
process = global_state.download_processes[task_id]
process.terminate()
process.join(timeout=2)
if process.is_alive():
process.kill()
except Exception as e:
print(f" 清理进程 {task_id} 时出错: {e}")
# 删除任务
del global_state.state["download_tasks"][task_id]
# 从active_downloads中移除
if task_id in global_state.active_downloads:
del global_state.active_downloads[task_id]
# 从download_processes中移除
if task_id in global_state.download_processes:
del global_state.download_processes[task_id]
print("测试完成")
return True
if __name__ == "__main__":
success = test_pause_with_next_task()
sys.exit(0 if success else 1)
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment