CoolFace
Apppublic

Limour/llama-python-streamingllm

sourceHugging Facegpl-3.0updated 2y agoView on Hugging Face
1likes
app.py48 linesDownload Raw Back to root
1import subprocess2import select3import os4from mods.btn_reset import restart_space5 6if not os.path.exists('models/causallm_14b.Q4_0.gguf'):7    from huggingface_hub import snapshot_download8    os.mkdir("models")9    os.mkdir("cache")10    snapshot_download(repo_id='TheBloke/CausalLM-14B-GGUF', local_dir=r'models',11                      allow_patterns='causallm_14b.Q4_0.gguf')12    snapshot_download(repo_id='Limour/llama-python-streamingllm-cache', 13                      repo_type='dataset', local_dir=r'cache', 14                      allow_patterns='f051fe319ada24080ea38869dba6bdfac79d5a84')15 16try:17    # 启动另一个程序,并通过管道捕获其输出18    process = subprocess.Popen(["python", "gradio_streamingllm.py"],19                               stdout=subprocess.PIPE,20                               stderr=subprocess.PIPE,21                               bufsize=1, universal_newlines=True)22    while process.poll() is None:23        # 使用 select 模块检查是否有可读数据24        ready_reads, _, _ = select.select([process.stdout, process.stderr], [], [])25        if not ready_reads:26            print('select.select timeout')27        for ready in ready_reads:28            # 读取输出并打印29            output = ready.readline()30            if output:31                print(output, end='')32            else:33                print('select.select timeout')34 35    # 读取剩余的输出36    for output in process.stdout.readlines() + process.stderr.readlines():37        print(output, end='')38 39    # 检查进程的返回代码以确定是否成功结束40    if process.returncode == 0:41        print("Process has terminated successfully.")42    else:43        print(f"Process has terminated with an error. {process.returncode}")44 45finally:46    # restart_space()47    pass48