Zedel17 commited on
Commit
3426b1d
·
1 Parent(s): e93cd54

Fix Tentative n3

Browse files
Files changed (2) hide show
  1. app.py +10 -21
  2. requirements.txt +1 -1
app.py CHANGED
@@ -1,35 +1,24 @@
1
  import gradio as gr
2
- import os
3
- from huggingface_hub import hf_hub_download
4
  from ctransformers import AutoModelForCausalLM
5
 
6
- # Configuration
7
  HF_REPO = "Zedel17/llama_1b_gguf"
8
- GGUF_FILE = "llama_1b_finetuned-Q4_K_M.gguf" # make sure this EXACT name exists in the repo
9
-
10
- # Get HF token from Space secrets (optional if repo is public)
11
- hf_token = os.environ.get("HF_TOKEN")
12
-
13
- print("Downloading GGUF model from HuggingFace...\n")
14
- model_path = hf_hub_download(
15
- repo_id=HF_REPO,
16
- filename=GGUF_FILE,
17
- token=hf_token, # ok here – this is huggingface_hub, not ctransformers
18
- )
19
- print(f"Model downloaded to: {model_path}")
20
 
21
  print("Loading GGUF model with ctransformers...")
 
22
  llm = AutoModelForCausalLM.from_pretrained(
23
- model_path, # local path to the .gguf file
24
- model_type="llama", # LLaMA / LLaMA 3.x family
25
- context_length=2048,
26
- gpu_layers=0, # CPU only (free HF Space)
27
- threads=2, # free Space usually has 2 vCPUs
 
 
28
  )
 
29
  print("Model loaded successfully!")
30
 
31
  def chat(message, history):
32
- # Simple conversation formatting
33
  parts = []
34
  for user_msg, bot_msg in history:
35
  parts.append(f"User: {user_msg}\nAssistant: {bot_msg}")
 
1
  import gradio as gr
 
 
2
  from ctransformers import AutoModelForCausalLM
3
 
 
4
  HF_REPO = "Zedel17/llama_1b_gguf"
5
+ GGUF_FILE = "llama_1b_finetuned-Q4_K_M.gguf"
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  print("Loading GGUF model with ctransformers...")
8
+
9
  llm = AutoModelForCausalLM.from_pretrained(
10
+ HF_REPO,
11
+ model_file=GGUF_FILE,
12
+ model_type="llama",
13
+ hf=True,
14
+ gpu_layers=0, # CPU-only on free Spaces
15
+ threads=2, # free tier: 2 vCPUs
16
+ context_length=2048
17
  )
18
+
19
  print("Model loaded successfully!")
20
 
21
  def chat(message, history):
 
22
  parts = []
23
  for user_msg, bot_msg in history:
24
  parts.append(f"User: {user_msg}\nAssistant: {bot_msg}")
requirements.txt CHANGED
@@ -1,4 +1,4 @@
1
  gradio
2
  huggingface_hub
3
- ctransformers
4
 
 
1
  gradio
2
  huggingface_hub
3
+ ctransformers>=0.2.27
4