AskGemma / app_utils.py
abhidgp1978's picture
Update app_utils.py
a5158ea verified
Raw History Blame Contribute Delete
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
)