1. 修改了文件上传的功能

This commit is contained in:
2026-01-12 11:22:46 +08:00
parent 6e1b4b58ba
commit 45276a7787
15 changed files with 439 additions and 1140 deletions

View File

@@ -1,95 +0,0 @@
# 🔥 大模型微调平台
> **静态HTML页面使用假数据模拟系统监控**
## 🚀 快速启动
### 方式1: 直接打开文件(推荐)
```bash
cd web
./start.sh
```
选择 `1` 直接打开文件
### 方式2: HTTP服务器可通过IP访问
```bash
cd web
./start.sh
```
选择 `2` 启动HTTP服务器
或直接运行:
```bash
./start-http-server.sh
```
## 📊 访问应用
### 直接打开文件
- **主页**: `file:///data/code/FT_Platform/YG_FT_Platform/web/pages/main.html`
- **登录**: `file:///data/code/FT_Platform/YG_FT_Platform/web/pages/login.html`
### HTTP服务器访问端口8000
- **主页**: `http://10.10.10.77:8000/pages/main.html`
- **登录**: `http://10.10.10.77:8000/pages/login.html`
## ✅ 模拟系统数据
现在显示的是**模拟数据**:
-**CPU使用率**: 随机模拟数据
-**内存使用率**: 随机模拟数据
-**GPU使用率**: 随机模拟数据
每2秒自动更新一次数据
## 🔧 技术架构
- **前端**: HTML + CSS + JavaScript
- **图表**: Chart.js
- **样式**: Tailwind CSS
- **服务器**: Python HTTP服务器可选
## 📱 特性
- 静态HTML页面无需后端服务
- 模拟数据自动更新
- 响应式设计 (支持手机/平板)
- 20个数据点滚动显示
- 彩色编码 (CPU红色, GPU绿色, 内存蓝色)
## 🛑 停止服务器
### 停止HTTP服务器
```bash
# 按 Ctrl+C
```
## 🐛 故障排除
### 问题: 找不到Python
**解决**: 安装Python或使用方式1直接打开文件
### 问题: 端口8000被占用
**解决**:
```bash
# 找到占用端口的进程
lsof -i :8000
# 或使用其他端口
python3 -m http.server 8001
```
### 问题: IP地址无法访问
**解决**:
1. 确保使用HTTP服务器方式启动
2. 检查防火墙设置确保端口8000开放
3. 使用正确的IP地址
### 问题: 数据不更新
**解决**: 刷新页面或重新启动
## 📞 获取帮助
如果遇到问题:
1. 首先尝试方式1直接打开文件
2. 如果需要IP访问使用方式2启动HTTP服务器
3. 检查Python是否安装

0
web/nul Normal file
View File

View File

@@ -755,7 +755,7 @@
};
// 数据集管理相关功能
const API_BASE = 'http://10.10.10.77:8001/api';
const API_BASE = 'http://localhost:3000/api';
// 加载数据集列表
async function loadDatasets() {
@@ -763,8 +763,11 @@
const response = await fetch(`${API_BASE}/datasets`);
const result = await response.json();
if (result.code === 200) {
renderDatasetList(result.data.datasets);
// 适配StandardResponse格式: {status: 1, response: {...}}
if (result.status === 1 && result.response && result.response.datasets) {
renderDatasetList(result.response.datasets);
} else if (result.status === 0) {
console.error('加载数据集列表失败:', result.response?.error || '未知错误');
}
} catch (error) {
console.error('加载数据集列表失败:', error);
@@ -788,11 +791,12 @@
<div class="flex justify-between items-center">
<div>
<h3 class="font-medium text-dashboard-text">${dataset.name}</h3>
<p class="text-sm text-dashboard-textLight mt-1">${dataset.size || '未知大小'}${dataset.records_count || dataset.description || '未知'}</p>
<p class="text-sm text-dashboard-textLight mt-1">${dataset.size_display || dataset.size_mb + ' MB' || '未知大小'}${dataset.description || '无描述'}</p>
</div>
<div class="flex items-center space-x-2">
<span class="px-2 py-1 ${statusClass} text-xs rounded">${statusText}</span>
<button class="text-dashboard-primary hover:underline text-sm">查看详情</button>
<button onclick="viewDatasetDetails('${dataset.file_id}')" class="text-dashboard-primary hover:underline text-sm">查看详情</button>
<button onclick="deleteDataset('${dataset.file_id}', '${dataset.name}')" class="text-red-500 hover:text-red-700 text-sm">删除</button>
</div>
</div>
`;
@@ -814,6 +818,7 @@
}
}
// 查看数据集详情
// 处理文件上传
async function handleFileUpload(input) {
const file = input.files[0];
@@ -849,12 +854,14 @@
const result = await response.json();
if (result.code === 200) {
// 适配StandardResponse格式: {status: 1, response: {...}}
if (result.status === 1) {
alert('上传成功!');
// 重新加载数据集列表
loadDatasets();
} else {
alert('上传失败: ' + (result.detail || result.message || '未知错误'));
const errorMsg = result.response?.error || result.message || '未知错误';
alert('上传失败: ' + errorMsg);
}
} catch (error) {
console.error('上传失败:', error);
@@ -872,6 +879,151 @@
// 跳转到登录页面
window.location.href = 'login.html';
}
// 查看数据集详情
async function viewDatasetDetails(fileId) {
try {
// 调用API获取文件内容
const response = await fetch(`${API_BASE}/datasets/${fileId}/content?limit=5`);
const result = await response.json();
if (result.status === 1) {
const data = result.response;
let contentHtml = '';
if (Array.isArray(data.preview)) {
// 如果是数组显示前5条记录
contentHtml = '<div style="max-height: 400px; overflow-y: auto;"><pre>' +
JSON.stringify(data.preview, null, 2) +
'</pre></div>';
} else {
// 如果是对象,直接显示
contentHtml = '<div style="max-height: 400px; overflow-y: auto;"><pre>' +
JSON.stringify(data.preview, null, 2) +
'</pre></div>';
}
// 显示模态框
showDatasetModal(data.filename, contentHtml);
} else {
alert('获取文件内容失败: ' + (result.response?.error || '未知错误'));
}
} catch (error) {
console.error('获取文件详情失败:', error);
alert('获取文件详情失败: 网络错误');
}
}
// 显示数据集详情模态框
function showDatasetModal(title, content) {
const modal = document.createElement('div');
modal.style.cssText = `
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
z-index: 10000;
`;
const modalContent = document.createElement('div');
modalContent.style.cssText = `
background: white;
padding: 20px;
border-radius: 8px;
max-width: 800px;
max-height: 600px;
overflow: hidden;
display: flex;
flex-direction: column;
`;
const modalHeader = document.createElement('div');
modalHeader.style.cssText = `
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 15px;
border-bottom: 1px solid #eee;
padding-bottom: 10px;
`;
const titleElement = document.createElement('h3');
titleElement.textContent = title;
titleElement.style.cssText = 'margin: 0; color: #333;';
const closeButton = document.createElement('button');
closeButton.textContent = '×';
closeButton.style.cssText = `
background: none;
border: none;
font-size: 24px;
cursor: pointer;
color: #666;
width: 30px;
height: 30px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 4px;
`;
closeButton.onmouseover = () => closeButton.style.background = '#f0f0f0';
closeButton.onmouseout = () => closeButton.style.background = 'none';
const closeModal = () => {
document.body.removeChild(modal);
};
closeButton.onclick = closeModal;
modal.onclick = (e) => {
if (e.target === modal) closeModal();
};
modalHeader.appendChild(titleElement);
modalHeader.appendChild(closeButton);
const contentDiv = document.createElement('div');
contentDiv.innerHTML = content;
modalContent.appendChild(modalHeader);
modalContent.appendChild(contentDiv);
modal.appendChild(modalContent);
document.body.appendChild(modal);
}
// 删除数据集
async function deleteDataset(fileId, filename) {
// 确认删除对话框
const confirmMessage = `确定要删除数据集 "${filename}" 吗?\n\n此操作不可撤销!`;
if (!confirm(confirmMessage)) {
return;
}
try {
const response = await fetch(`${API_BASE}/datasets/${fileId}`, {
method: 'DELETE'
});
const result = await response.json();
if (result.status === 1) {
alert('删除成功!');
// 重新加载数据集列表
loadDatasets();
} else {
alert('删除失败: ' + (result.response?.error || '未知错误'));
}
} catch (error) {
console.error('删除失败:', error);
alert('删除失败: 网络错误');
}
}
</script>
</body>

View File

@@ -1,36 +1,135 @@
#!/bin/bash
echo "🚀 启动 HTTP 服务器..."
echo "🚀 启动 HTTP 服务器"
echo "===================="
echo ""
# 确保在正确的目录
# 获取脚本所在目录
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
echo "📂 当前目录: $SCRIPT_DIR"
echo ""
# 获取本机IP地址
SERVER_IP=$(hostname -I | awk '{print $1}')
echo "🌐 本机 IP 地址: $SERVER_IP"
# 检测操作系统类型
echo "🔍 检测操作系统..."
OSTYPE_LOWER=$(echo "$OSTYPE" | tr '[:upper:]' '[:lower:]')
# 检测是否在 WSL 中
IS_WSL=0
if [[ -n "$WSLENV" ]] || grep -qi microsoft /proc/version 2>/dev/null; then
IS_WSL=1
OS_TYPE="WSL (Windows Subsystem for Linux)"
echo "📟 检测到 WSL 环境"
elif [[ "$OSTYPE_LOWER" == "linux-gnu"* ]]; then
OS_TYPE="Linux"
echo "🐧 检测到 Linux 环境"
elif [[ "$OSTYPE_LOWER" == "darwin"* ]]; then
OS_TYPE="macOS"
echo "🍎 检测到 macOS 环境"
elif [[ "$OSTYPE_LOWER" == "msys" ]] || [[ "$OSTYPE_LOWER" == "cygwin" ]]; then
OS_TYPE="Windows (MSYS/Cygwin)"
echo "🪟 检测到 Windows (MSYS/Cygwin) 环境"
else
OS_TYPE="Unknown"
echo "⚠️ 未识别的操作系统: $OSTYPE"
fi
echo "✅ 操作系统类型: $OS_TYPE"
echo ""
# 根据操作系统选择 Python 命令
PYTHON_CMD=""
PYTHON_VERSION=""
# 检查Python是否可用
if command -v python3 &> /dev/null; then
PYTHON_CMD="python3"
PYTHON_VERSION=$(python3 --version 2>&1)
elif command -v python &> /dev/null; then
PYTHON_CMD="python"
PYTHON_VERSION=$(python --version 2>&1)
else
echo "❌ 错误: 未找到 Python"
echo "请安装 Python 或手动打开文件"
echo ""
echo "💡 解决方案:"
echo " 1. 安装 Python 3.x"
echo " 2. 确保 python 或 python3 命令可用"
echo " 3. Windows 用户可以使用: start.bat"
echo ""
exit 1
fi
echo "✅ 使用 Python 命令: $PYTHON_CMD"
echo "✅ Python 版本: $PYTHON_VERSION"
echo ""
# 获取本机IP地址
SERVER_IP=""
case "$OS_TYPE" in
"Linux"|"macOS")
# Linux/macOS 使用 hostname -I
if command -v hostname &> /dev/null; then
SERVER_IP=$(hostname -I 2>/dev/null | awk '{print $1}' | head -n1)
if [ -n "$SERVER_IP" ] && [ "$SERVER_IP" != "localhost" ]; then
echo "🌐 检测到 IP 地址: $SERVER_IP"
else
echo "🌐 未检测到有效 IP将使用 localhost"
SERVER_IP="localhost"
fi
fi
;;
"WSL (Windows Subsystem for Linux)")
echo "💡 WSL 环境提示:"
echo " - 如果无法访问 localhost请检查 WSL 网络配置"
echo " - 建议在 Windows 浏览器中访问服务"
echo ""
echo "🌐 建议使用: http://localhost:8000 访问"
SERVER_IP="localhost"
;;
"Windows (MSYS/Cygwin)"|*)
# Windows 下使用 localhost 更可靠
echo "🌐 Windows 环境使用 localhost 访问"
SERVER_IP="localhost"
;;
esac
if [ -z "$SERVER_IP" ]; then
SERVER_IP="localhost"
fi
echo ""
echo "📱 访问地址:"
echo " - 主页: http://$SERVER_IP:8000/pages/main.html"
echo " - 登录: http://$SERVER_IP:8000/pages/login.html"
echo " 主页: http://$SERVER_IP:8000/pages/main.html"
echo " 登录: http://$SERVER_IP:8000/pages/login.html"
echo ""
echo "⚠️ 服务器将在端口 8000 启动"
echo "按 Ctrl+C 停止服务器"
echo ""
# 启动HTTP服务器
# 启动 HTTP 服务器
echo "🔧 启动中..."
echo ""
# WSL 环境特殊处理
if [ $IS_WSL -eq 1 ]; then
echo "💡 WSL 启动提示:"
echo " - 服务器在 WSL 中启动"
echo " - 如果 Windows 浏览器无法访问,可能需要配置 WSL 网络"
echo " - 或使用 Windows 的 Python 启动: python -m http.server 8000"
echo ""
fi
# 启动服务器
$PYTHON_CMD -m http.server 8000
EXIT_CODE=$?
if [ $EXIT_CODE -ne 0 ]; then
echo ""
echo "❌ 服务器启动失败 (退出码: $EXIT_CODE)"
echo ""
echo "💡 故障排除:"
echo " 1. 检查端口 8000 是否被占用"
echo " 2. 确认 Python 3 已正确安装"
echo " 3. 尝试使用其他端口: $PYTHON_CMD -m http.server 9000"
echo ""
fi

157
web/start.bat Normal file
View File

@@ -0,0 +1,157 @@
@echo off
chcp 65001 >nul
title FT-Platform Web 前端
echo.
echo 🚀 启动大模型微调平台 (Web 前端)
echo ========================================
echo.
:: 确保在正确的目录中
cd /d "%~dp0"
echo 📂 当前目录: %CD%
echo.
:: 检测运行环境
if not "%WSLENV%"=="" (
echo 📟 检测到 WSL 环境
set "IS_WSL=1"
) else (
echo 📟 检测到 Windows 环境
set "IS_WSL=0"
)
echo.
echo 请选择启动方式:
echo 1) 直接打开文件(本地访问)
echo 2) 启动HTTP服务器推荐跨域访问
echo 3) 使用 Python 启动 HTTP 服务器
echo.
set /p choice="请输入选择 (1-3): "
if "%choice%"=="1" goto open_file
if "%choice%"=="2" goto start_http
if "%choice%"=="3" goto start_python
echo ❌ 无效选择
pause
exit /b 1
:open_file
echo.
echo 🌐 打开本地文件...
echo.
echo 主页: file://%CD%\pages\main.html
echo 登录: file://%CD%\pages\login.html
echo.
:: 尝试打开浏览器
if exist "pages\main.html" (
start "FT-Platform 主页" "pages\main.html"
echo ✅ 已尝试在浏览器中打开主页
) else (
echo ❌ 未找到 pages\main.html 文件
)
echo.
echo 💡 如果浏览器未自动打开,请手动双击打开:
echo %CD%\pages\main.html
echo.
pause
goto end
:start_http
echo.
echo 🌐 启动 HTTP 服务器...
echo.
:: 检查 Python 命令
python --version >nul 2>&1
if %errorlevel% equ 0 (
set "PYTHON_CMD=python"
goto run_server
)
python3 --version >nul 2>&1
if %errorlevel% equ 0 (
set "PYTHON_CMD=python3"
goto run_server
)
echo ❌ 未找到 Python
echo.
echo 💡 请安装 Python 或选择方式 1 直接打开文件
echo.
pause
goto end
:start_python
echo.
echo 🌐 使用 Python 启动 HTTP 服务器...
echo.
:: 尝试多种 Python 命令
where python >nul 2>&1
if %errorlevel% equ 0 (
set "PYTHON_CMD=python"
goto run_server
)
where python3 >nul 2>&1
if %errorlevel% equ 0 (
set "PYTHON_CMD=python3"
goto run_server
)
echo ❌ 未找到 Python 命令
echo.
echo 💡 请检查 Python 是否已安装并添加到 PATH
echo.
pause
goto end
:run_server
echo ✅ 使用命令: %PYTHON_CMD%
echo.
:: 获取本机IP如果可能
for /f "tokens=2 delims=:" %%a in ('ipconfig ^| findstr /i "IPv4" ^| findstr /v "127.0.0.1"') do (
set "SERVER_IP=%%a"
goto :ip_found
)
:ip_found
if defined SERVER_IP (
echo 🌐 检测到 IP: %SERVER_IP%
) else (
echo 🌐 使用 localhost 访问
set "SERVER_IP=localhost"
)
echo.
echo 📱 访问地址:
echo 主页: http://%SERVER_IP%:8000/pages/main.html
echo 登录: http://%SERVER_IP%:8000/pages/login.html
echo.
echo ⚠️ 服务器启动在端口 8000
echo 按 Ctrl+C 停止服务器
echo.
if "%IS_WSL%"=="1" (
echo 💡 WSL 环境提示: 如果无法访问 localhost请检查网络配置
echo.
)
:: 启动服务器
echo 🔧 启动中...
echo.
%PYTHON_CMD% -m http.server 8000
if %errorlevel% neq 0 (
echo.
echo ❌ 启动失败,请检查 Python 环境
pause
)
:end

View File

@@ -1,82 +0,0 @@
#!/bin/bash
echo "🚀 启动大模型微调平台..."
echo ""
# 确保在正确的目录中
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
echo "📂 当前目录: $SCRIPT_DIR"
echo ""
# 获取本机IP地址
SERVER_IP=$(hostname -I | awk '{print $1}')
echo "请选择启动方式:"
echo "1) 直接打开文件(本地访问)"
echo "2) 启动HTTP服务器可通过IP访问"
echo ""
read -p "请输入选择 (1-2): " choice
case $choice in
1)
echo ""
echo "🌐 打开本地文件..."
echo " - 主页: file://$SCRIPT_DIR/pages/main.html"
echo " - 登录: file://$SCRIPT_DIR/pages/login.html"
echo ""
# 检测操作系统并打开浏览器
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
open "pages/main.html"
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
# Linux
xdg-open "pages/main.html"
elif [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "cygwin" ]]; then
# Windows (Git Bash or Cygwin)
start "pages/main.html"
else
echo "请手动打开以下文件:"
echo " $SCRIPT_DIR/pages/main.html"
fi
echo "✅ 已在浏览器中打开主页"
;;
2)
echo ""
echo "🌐 本机 IP 地址: $SERVER_IP"
echo ""
# 检查Python是否可用
if command -v python3 &> /dev/null; then
PYTHON_CMD="python3"
elif command -v python &> /dev/null; then
PYTHON_CMD="python"
else
echo "❌ 错误: 未找到 Python"
echo "请安装 Python 或使用方式 1 直接打开文件"
exit 1
fi
echo "📱 访问地址:"
echo " - 主页: http://$SERVER_IP:8000/pages/main.html"
echo " - 登录: http://$SERVER_IP:8000/pages/login.html"
echo ""
echo "⚠️ 服务器将在端口 8000 启动"
echo "按 Ctrl+C 停止服务器"
echo ""
# 启动HTTP服务器
$PYTHON_CMD -m http.server 8000
;;
*)
echo "❌ 无效选择,请运行脚本重新选择"
exit 1
;;
esac