CMLL's picture
Update app.py
a9638ab verified
raw
history blame contribute delete
No virus
2.29 kB
import os
import subprocess
def run_command(command):
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
stdout, stderr = process.communicate()
if process.returncode != 0:
raise Exception(f"Command failed with error: {stderr}")
return stdout
def main():
# Clone the repository
print("Cloning the repository...")
run_command("git clone https://github.com/ggerganov/llama.cpp.git")
# Change directory to the cloned repository
os.chdir("llama.cpp")
# Download the file
print("Downloading the GGUF file...")
run_command("wget -O ZhongJing1_5-1_8b-q4_0.gguf https://huggingface.co/CMLL/ZhongJing-2-1_8b-GGUF/resolve/main/ZhongJing1_5-1_8b-q4_0.gguf?download=true")
# Compile the project
print("Compiling the project...")
run_command("make")
# Modify the prompts/chat-with-bob.txt file
print("Modifying the chat-with-bob.txt file...")
dialog_content = """
Transcript of a dialog, where the User interacts with an Assistant named Bob. Bob is a helpful TCM medical assistant, also named 仲景中医大语言模型, and never fails to answer the User's requests immediately and with precision.
User: Hello, Bob.
Bob: Hello. How may I help you today?不断地从书中获取知识,以获得更全面的知识结构。
"""
with open("prompts/chat-with-bob.txt", "w") as f:
f.write(dialog_content)
# Run the llama-cli command
print("Running the llama-cli command...")
process = subprocess.Popen(
['./llama-cli', '-m', 'ZhongJing1_5-1_8b-q4_0.gguf', '-n', '256', '--repeat_penalty', '1.0', '--color', '-i', '-r', 'User:', '-f', 'prompts/chat-with-bob.txt'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
# Capture the output and filter it
while True:
output = process.stdout.readline()
if 'Transcript of a dialog' in output:
print(output, end='')
break
while True:
output = process.stdout.readline()
if output.startswith('User:') or output.startswith('Bob:'):
print(output, end='')
elif process.poll() is not None:
break
if __name__ == "__main__":
main()