Spaces:
Runtime error
Runtime error
Download app_utils.py from abhidgp1978/AskGemma: direct link, hf CLI and curl.
- Browser
- Download file 1.07 kB
-
https://huggingface.co/spaces/abhidgp1978/AskGemma/resolve/main/app_utils.py
- Command line
-
hf download hf://spaces/abhidgp1978/AskGemma/app_utils.py
-
curl -L -o app_utils.py https://huggingface.co/spaces/abhidgp1978/AskGemma/resolve/main/app_utils.py
1.07 kB
| import os | |
| import requests | |
| from pathlib import Path | |
| from ctransformers import AutoModelForCausalLM | |
| # β Auto-download TinyLlama from your HF repo if not present | |
| MODEL_URL = "https://huggingface.co/abhidgp1978/abhi-model/resolve/main/tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf" | |
| MODEL_PATH = Path("models/tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf") | |
| MODEL_PATH.parent.mkdir(parents=True, exist_ok=True) | |
| if not MODEL_PATH.exists(): | |
| print("π Downloading TinyLlama model...") | |
| r = requests.get(MODEL_URL, stream=True) | |
| with open(MODEL_PATH, "wb") as f: | |
| for chunk in r.iter_content(chunk_size=8192): | |
| if chunk: | |
| f.write(chunk) | |
| print("β Model download complete.") | |
| # β Load TinyLlama locally | |
| llm = AutoModelForCausalLM.from_pretrained( | |
| str(MODEL_PATH), | |
| model_type="llama", | |
| gpu_layers=0 | |
| ) | |
| # β Standard LLM call | |
| def llm_call(prompt, max_tokens=256, stream=False): | |
| return llm( | |
| prompt, | |
| max_new_tokens=max_tokens, | |
| temperature=0.7, | |
| stop=["User:", "Assistant:"], | |
| stream=stream | |
| ) | |