# 配置环境 import subprocess # 克隆GitHub仓库 subprocess.run(["git", "clone", "https://github.com/hiyouga/LLaMA-Factory.git"], check=True) # 切换到仓库目录 import os os.chdir("LLaMA-Factory") # 安装unsloth subprocess.run(["pip", "install", "unsloth[colab-new]@git+https://github.com/unslothai/unsloth.git"], check=True) # 安装xformers subprocess.run(["pip", "install", "-U", "xformers==0.0.25"], check=True) # 安装当前目录下的依赖 subprocess.run(["pip", "install", ".[torch,bitsandbytes]"], check=True) import gradio as gr from llamafactory.chat import ChatModel from llamafactory.extras.misc import torch_gc import re def split_into_sentences(text): sentence_endings = re.compile(r'(?