Download ai.py from SWYfisher/AI_test: direct link, hf CLI and curl.
- Browser
- Download file 1.36 kB
-
https://huggingface.co/spaces/SWYfisher/AI_test/resolve/main/ai.py
- Command line
-
hf download hf://spaces/SWYfisher/AI_test/ai.py
-
curl -L -o ai.py https://huggingface.co/spaces/SWYfisher/AI_test/resolve/main/ai.py
1.36 kB
| import os | |
| from huggingface_hub import hf_hub_download | |
| from llama_cpp import Llama | |
| # Define the model details | |
| model_name = "mradermacher/Llama3.3-8B-Instruct-Thinking-Heretic-Uncensored-Claude-4.5-Opus-High-Reasoning-i1-GGUF" # Changing to Deepseek Coder Instruct (6.7B parameters) | |
| model_file = "Llama3.3-8B-Instruct-Thinking-Heretic-Uncensored-Claude-4.5-Opus-High-Reasoning.i1-Q6_K.gguf" # A quantized model file for Deepseek Coder | |
| # Define the path where the model will be downloaded | |
| model_path = os.path.join(os.getcwd(), model_file) | |
| # Download the model if it doesn't exist | |
| if not os.path.exists(model_path): | |
| print(f"Downloading {model_file} from Hugging Face Hub...") | |
| hf_hub_download( | |
| repo_id=model_name, | |
| filename=model_file, | |
| local_dir=os.getcwd(), | |
| local_dir_use_symlinks=False, | |
| ) | |
| print("Download complete.") | |
| else: | |
| print(f"{model_file} already exists, skipping download.") | |
| # Initialize the Llama model | |
| print("Initializing Llama model...") | |
| llm = Llama(model_path=model_path, n_ctx=2048, n_gpu_layers=-1) | |
| print("Model initialized.") | |
| # Example of using the model | |
| prompt = "Q: What is the capital of China? A:" | |
| print(f"\nUser: {prompt}") | |
| output = llm( | |
| prompt, | |
| max_tokens=2048, | |
| stop=["Q:", "\n"], | |
| echo=True, | |
| temperature=0.7, | |
| ) | |
| print("LLM Output:") | |
| print(output["choices"][0]["text"]) |