Update app.py
Browse files1 unmodified line2345678910111213141516171819202122231 unmodified linefrom llama_cpp import Llamafrom huggingface_hub import hf_hub_downloadprint("Loading model... please wait.")model_path = hf_hub_download(repo_id="mradermacher/Qwen2.5-Coder-32B-Instruct-GGUF",filename="Qwen2.5-Coder-32B-Instruct.Q2_K.gguf")llm = Llama(model_path=model_path, n_ctx=2048)def respond(message, history):prompt = f"System: You are a helpful AI.\nUser: {message}\nAssistant:"output = llm(prompt, max_tokens=512, stop=["User:"], echo=False)return output["choices"][0]["text"]demo = gr.ChatInterface(fn=respond, title="Qwen 32B Coder (CPU)")if __name__ == "__main__":demo.launch()1 unmodified line23456789101112131415161718192021222324252627282930313233343536373839401 unmodified linefrom llama_cpp import Llamafrom huggingface_hub import hf_hub_downloadprint("Loading 7B Model into CPU RAM...")model_path = hf_hub_download(repo_id="Qwen/Qwen2.5-Coder-7B-Instruct-GGUF",filename="qwen2.5-coder-7b-instruct-q4_k_m.gguf")llm = Llama(model_path=model_path,n_ctx=1024,n_threads=2,n_batch=512)def respond(message, history):prompt = f"<|im_start|>system\nYou are a professional coder.<|im_end|>\n"for user_msg, assistant_msg in history:prompt += f"<|im_start|>user\n{user_msg}<|im_end|>\n<|im_start|>assistant\n{assistant_msg}<|im_end|>\n"prompt += f"<|im_start|>user\n{message}<|im_end|>\n<|im_start|>assistant\n"response_text = ""stream = llm(prompt,max_tokens=512,stop=["<|im_end|>"],stream=True)for chunk in stream:token = chunk["choices"][0]["text"]response_text += tokenyield response_textdemo = gr.ChatInterface(respond)if __name__ == "__main__":demo.launch()
app.py+27-10