Spaces:
Runtime error
Runtime error
| from ctransformers import AutoModelForCausalLM | |
| from huggingface_hub import hf_hub_download | |
| import gradio as gr | |
| model_path = hf_hub_download( | |
| repo_id="RavikxxBGamin/MinecraftAI", | |
| filename="llama-3.2-3b-instruct.Q4_K_M.gguf" | |
| ) | |
| llm = AutoModelForCausalLM.from_pretrained( | |
| model_path, | |
| model_type="llama", | |
| context_length=4096, | |
| max_new_tokens=1024, | |
| temperature=0.7, | |
| local_files_only=True | |
| ) | |
| SYSTEM_PROMPT = "You are a helpful Minecraft plugin development and Java programming assistant. You are patient and explanatory. Always format code inside code blocks." | |
| def chat(message, history): | |
| prompt = "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n" + SYSTEM_PROMPT + "<|eot_id|>" | |
| for user_msg, assistant_msg in history: | |
| prompt += "<|start_header_id|>user<|end_header_id|>\n" + user_msg + "<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n" + assistant_msg + "<|eot_id|>" | |
| prompt += "<|start_header_id|>user<|end_header_id|>\n" + message + "<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n" | |
| response = llm(prompt) | |
| return response | |
| gr.ChatInterface( | |
| fn=chat, | |
| title="MinecraftAI", | |
| description="A Minecraft plugin development and Java programming assistant" | |
| ).launch() |