File size: 1,801 Bytes
6b70385
009cabd
0523803
 
 
5383570
0523803
ed568ad
0523803
5383570
 
 
 
8ba02a5
6b70385
 
 
0523803
009cabd
 
 
 
 
d762eb5
 
 
009cabd
 
 
 
 
d762eb5
 
009cabd
 
 
 
 
 
 
 
 
 
 
6b70385
dd67af6
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import subprocess
import select
import os
from mods.btn_reset import restart_space

if not os.path.exists('models/causallm_14b.Q4_0.gguf'):
    from huggingface_hub import snapshot_download
    os.mkdir("models")
    os.mkdir("cache")
    snapshot_download(repo_id='TheBloke/CausalLM-14B-GGUF', local_dir=r'models',
                      allow_patterns='causallm_14b.Q4_0.gguf')
    snapshot_download(repo_id='Limour/llama-python-streamingllm-cache', 
                      repo_type='dataset', local_dir=r'cache', 
                      allow_patterns='f051fe319ada24080ea38869dba6bdfac79d5a84')

try:
    # 启动另一个程序,并通过管道捕获其输出
    process = subprocess.Popen(["python", "gradio_streamingllm.py"],
                               stdout=subprocess.PIPE,
                               stderr=subprocess.PIPE,
                               bufsize=1, universal_newlines=True)
    while process.poll() is None:
        # 使用 select 模块检查是否有可读数据
        ready_reads, _, _ = select.select([process.stdout, process.stderr], [], [])
        if not ready_reads:
            print('select.select timeout')
        for ready in ready_reads:
            # 读取输出并打印
            output = ready.readline()
            if output:
                print(output, end='')
            else:
                print('select.select timeout')

    # 读取剩余的输出
    for output in process.stdout.readlines() + process.stderr.readlines():
        print(output, end='')

    # 检查进程的返回代码以确定是否成功结束
    if process.returncode == 0:
        print("Process has terminated successfully.")
    else:
        print(f"Process has terminated with an error. {process.returncode}")

finally:
    # restart_space()
    pass