start.bat 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. @echo off
  2. chcp 65001
  3. set no_proxy="127.0.0.1, 0.0.0.0, localhost"
  4. setlocal enabledelayedexpansion
  5. cd /D "%~dp0"
  6. set PATH="%PATH%";%SystemRoot%\system32
  7. :: 安装Miniconda
  8. :: 检查是否有特殊字符
  9. echo "%CD%"| findstr /R /C:"[!#\$%&()\*+,;<=>?@\[\]\^`{|}~\u4E00-\u9FFF ] " >nul && (
  10. echo.
  11. echo 当前路径中存在特殊字符,请使fish-speech的路径不含特殊字符后再运行。 && (
  12. goto end
  13. )
  14. )
  15. :: 解决跨驱动器安装问题
  16. set TMP=%CD%\fishenv
  17. set TEMP=%CD%\fishenv
  18. :: 取消激活已经激活的环境
  19. (call conda deactivate && call conda deactivate && call conda deactivate) 2>nul
  20. :: 安装路径配置
  21. set INSTALL_DIR=%cd%\fishenv
  22. set CONDA_ROOT_PREFIX=%cd%\fishenv\conda
  23. set INSTALL_ENV_DIR=%cd%\fishenv\env
  24. set PIP_CMD=%cd%\fishenv\env\python -m pip
  25. set PYTHON_CMD=%cd%\fishenv\env\python
  26. set API_FLAG_PATH=%~dp0API_FLAGS.txt
  27. set MINICONDA_DOWNLOAD_URL=https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py310_23.3.1-0-Windows-x86_64.exe
  28. set MINICONDA_CHECKSUM=307194e1f12bbeb52b083634e89cc67db4f7980bd542254b43d3309eaf7cb358
  29. set conda_exists=F
  30. :: 确定是否要安装conda
  31. call "%CONDA_ROOT_PREFIX%\_conda.exe" --version >nul 2>&1
  32. if "%ERRORLEVEL%" EQU "0" set conda_exists=T
  33. :: 下载Miniconda
  34. if "%conda_exists%" == "F" (
  35. echo.
  36. echo 正在下载Miniconda...
  37. mkdir "%INSTALL_DIR%" 2>nul
  38. :: 使用curl下载Miniconda安装程序
  39. call curl -Lk "%MINICONDA_DOWNLOAD_URL%" > "%INSTALL_DIR%\miniconda_installer.exe"
  40. :: 检查下载是否成功
  41. if errorlevel 1 (
  42. echo.
  43. echo 下载Miniconda失败
  44. goto end
  45. )
  46. :: 哈希校验
  47. for /f %%a in ('
  48. certutil -hashfile "%INSTALL_DIR%\miniconda_installer.exe" sha256
  49. ^| find /i /v " "
  50. ^| find /i "%MINICONDA_CHECKSUM%"
  51. ') do (
  52. :: 如果哈希值匹配预设的校验和,将其存储在变量中
  53. set "hash=%%a"
  54. )
  55. if not defined hash (
  56. echo.
  57. echo Miniconda安装程序的哈希值不匹配
  58. del "%INSTALL_DIR%\miniconda_installer.exe"
  59. goto end
  60. ) else (
  61. echo.
  62. echo Miniconda安装程序的哈希值成功匹配
  63. )
  64. echo 下载完成,接下来安装Miniconda至"%CONDA_ROOT_PREFIX%"
  65. start /wait "" "%INSTALL_DIR%\miniconda_installer.exe" /InstallationType=JustMe /NoShortcuts=1 /AddToPath=0 /RegisterPython=0 /NoRegistry=1 /S /D=%CONDA_ROOT_PREFIX%
  66. :: 测试是否成功安装
  67. call "%CONDA_ROOT_PREFIX%\_conda.exe" --version
  68. if errorlevel 1 (
  69. echo.
  70. echo 未安装Miniconda
  71. goto end
  72. ) else (
  73. echo.
  74. echo Miniconda安装成功
  75. )
  76. :: 删除安装程序
  77. del "%INSTALL_DIR%\miniconda_installer.exe"
  78. )
  79. :: 创建conda环境
  80. if not exist "%INSTALL_ENV_DIR%" (
  81. echo.
  82. echo 正在创建conda环境...
  83. call "%CONDA_ROOT_PREFIX%\_conda.exe" create --no-shortcuts -y -k --prefix "%INSTALL_ENV_DIR%" -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ python=3.10
  84. :: 检查环境创建是否成功
  85. if errorlevel 1 (
  86. echo.
  87. echo 创建conda环境失败
  88. goto end
  89. )
  90. )
  91. :: 检查是否真的创建了环境
  92. if not exist "%INSTALL_ENV_DIR%\python.exe" (
  93. echo.
  94. echo Conda环境不存在
  95. goto end
  96. )
  97. :: 环境隔离
  98. set PYTHONNOUSERSITE=1
  99. set PYTHONPATH=
  100. set PYTHONHOME=
  101. set "CUDA_PATH=%INSTALL_ENV_DIR%"
  102. set "CUDA_HOME=%CUDA_PATH%"
  103. :: 激活环境
  104. call "%CONDA_ROOT_PREFIX%\condabin\conda.bat" activate "%INSTALL_ENV_DIR%"
  105. :: 检查环境是否成功激活
  106. if errorlevel 1 (
  107. echo.
  108. echo 环境激活失败
  109. goto end
  110. ) else (
  111. echo.
  112. echo 环境激活成功
  113. )
  114. :: 安装依赖
  115. %PIP_CMD% show torch >nul 2>&1
  116. if errorlevel 1 (
  117. echo.
  118. echo 未安装pytorch,正在安装...
  119. %PIP_CMD% install torch --index-url https://mirror.sjtu.edu.cn/pytorch-wheels/cu121 --no-warn-script-location
  120. )
  121. %PIP_CMD% show torchvision >nul 2>&1
  122. if errorlevel 1 (
  123. echo.
  124. echo 未安装torchvision,正在安装...
  125. %PIP_CMD% install torchvision --index-url https://mirror.sjtu.edu.cn/pytorch-wheels/cu121 --no-warn-script-location
  126. )
  127. %PIP_CMD% show torchaudio >nul 2>&1
  128. if errorlevel 1 (
  129. echo.
  130. echo 未安装torchaudio,正在安装...
  131. %PIP_CMD% install torchaudio --index-url https://mirror.sjtu.edu.cn/pytorch-wheels/cu121 --no-warn-script-location
  132. )
  133. %PIP_CMD% show openai-whisper >nul 2>&1
  134. if errorlevel 1 (
  135. echo.
  136. echo 未安装openai-whisper,正在安装...
  137. %PIP_CMD% install -i https://pypi.tuna.tsinghua.edu.cn/simple openai-whisper --no-warn-script-location
  138. )
  139. %PIP_CMD% show fish-speech >nul 2>&1
  140. if errorlevel 1 (
  141. echo.
  142. echo 未安装fish-speech,正在安装...
  143. %PIP_CMD% install -e .
  144. )
  145. :: 设置Hugging Face镜像源
  146. set HF_ENDPOINT="https://hf-mirror.com"
  147. :: 设置API_FLAG
  148. :: 初始化API_FLAG
  149. set "API_FLAGS="
  150. set "flags="
  151. :: 检查API_FLAG文件是否存在
  152. if exist "%API_FLAG_PATH%" (
  153. for /f "usebackq tokens=*" %%a in ("%API_FLAG_PATH%") do (
  154. set "line=%%a"
  155. :: 去除行尾的反斜杠和空白字符,并且跳过以#开头的行
  156. if not "!line:~0,1!"=="#" (
  157. set "line=!line: =<SPACE>!"
  158. set "line=!line:\=!"
  159. set "line=!line:<SPACE>= !"
  160. if not "!line!"=="" (
  161. set "API_FLAGS=!API_FLAGS!!line! "
  162. )
  163. )
  164. )
  165. )
  166. :: 去除API_FLAGS变量最后的空格
  167. if not "!API_FLAGS!"=="" set "API_FLAGS=!API_FLAGS:~0,-1!"
  168. :: 看看开不开api推理
  169. echo !API_FLAGS! | findstr /C:"--api" >nul 2>&1
  170. if !errorlevel! equ 0 (
  171. echo.
  172. echo 启动HTTP API推理
  173. set "first_arg=true"
  174. for %%a in (%*) do (
  175. if "!first_arg!"=="true" (
  176. set "first_arg=false"
  177. ) else (
  178. if not "%%a"=="--api" (
  179. set "flags=!flags!%%a"
  180. )
  181. )
  182. )
  183. %PYTHON_CMD% -m tools.api !flags!
  184. ) else (
  185. if defined flags (
  186. :: 启动WebUI推理
  187. echo.
  188. echo 启动WebUI推理
  189. %PYTHON_CMD% -m tools.webui !flags!
  190. )
  191. )
  192. echo.
  193. echo 接下来启动页面
  194. %PYTHON_CMD% fish_speech\webui\manage.py
  195. :end
  196. pause