import gradio as gr import os from pathlib import Path import argparse model_file = "Yi-6B.q4_k_m.gguf" if not os.path.isfile("Yi-6B.q4_k_m.gguf"): os.system("wget -c https://huggingface.co/SamPurkis/Yi-6B-GGUF/resolve/main/Yi-6B.q4_k_m.gguf") DEFAULT_MODEL_PATH = model_file from llama_cpp import Llama llm = Llama(model_path=model_file) old_tokenize = llm._model.tokenize llm._model.tokenize = lambda text, add_bos, spec: old_tokenize(text, False, spec) def predict(input, chatbot, max_length, top_p, temperature, history): chatbot.append((input, "")) response = "" history.append(input) for output in llm(input, stream=True, temperature=temperature, top_p=top_p, max_tokens=max_length, ): piece = output['choices'][0]['text'] response += piece chatbot[-1] = (chatbot[-1][0], response) yield chatbot, history history.append(response) yield chatbot, history def reset_user_input(): return gr.update(value="") def reset_state(): return [], [] with gr.Blocks() as demo: gr.HTML("""