Zedel17 commited on
Commit
e93cd54
·
1 Parent(s): 4499d5f

Trying another fix to build

Browse files
Files changed (2) hide show
  1. app.py +17 -10
  2. requirements.txt +2 -1
app.py CHANGED
@@ -1,28 +1,35 @@
1
  import gradio as gr
2
  import os
 
3
  from ctransformers import AutoModelForCausalLM
4
 
5
  # Configuration
6
  HF_REPO = "Zedel17/llama_1b_gguf"
7
- GGUF_FILE = "llama_1b_finetuned-Q4_K_M.gguf"
8
 
 
9
  hf_token = os.environ.get("HF_TOKEN")
10
 
11
- print("Loading GGUF model with ctransformers...\n")
 
 
 
 
 
 
12
 
 
13
  llm = AutoModelForCausalLM.from_pretrained(
14
- HF_REPO, # repo on HF Hub
15
- model_file=GGUF_FILE, # exact GGUF filename
16
- model_type="llama", # Llama-family GGUF
17
- gpu_layers=0, # CPU only on free Spaces
18
- hf=True, # tell ctransformers it's an HF repo
19
- hf_token=hf_token # may be None if public
20
  )
21
-
22
  print("Model loaded successfully!")
23
 
24
  def chat(message, history):
25
- # Simple chat-style prompt
26
  parts = []
27
  for user_msg, bot_msg in history:
28
  parts.append(f"User: {user_msg}\nAssistant: {bot_msg}")
 
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}")
requirements.txt CHANGED
@@ -1,3 +1,4 @@
1
  gradio
2
  huggingface_hub
3
- ctransformers>=0.2.24
 
 
1
  gradio
2
  huggingface_hub
3
+ ctransformers
4
+