Austin Stockbridge commited on
Commit
bf9137e
·
verified ·
1 Parent(s): f9d8cf4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -15
app.py CHANGED
@@ -1,24 +1,27 @@
1
- import os
2
  from transformers import AutoModel, AutoTokenizer
3
 
4
- # Directory containing GGUF files
5
- gguf_directory = "/path/to/gguf/files" # Replace with your actual directory path
6
 
7
- # Filter files containing 'Q2_K'
8
- def find_q2_k_models(directory):
9
- return [file for file in os.listdir(directory) if "Q2_K" in file and file.endswith(".gguf")]
10
-
11
- # Load the appropriate model
12
- def load_q2_k_model(gguf_directory):
13
- q2_k_files = find_q2_k_models(gguf_directory)
14
  if not q2_k_files:
15
- raise ValueError("No GGUF files with 'Q2_K' found in the specified directory.")
16
- # Load the first matching file (or implement logic for user selection)
17
- model_path = os.path.join(gguf_directory, q2_k_files[0])
18
- print(f"Loading model from: {model_path}")
 
 
 
 
 
 
19
  model = AutoModel.from_pretrained(model_path)
20
  tokenizer = AutoTokenizer.from_pretrained(model_path)
21
  return model, tokenizer
22
 
23
  # Initialize the model
24
- model, tokenizer = load_q2_k_model(gguf_directory)
 
1
+ from huggingface_hub import hf_hub_list, hf_hub_download
2
  from transformers import AutoModel, AutoTokenizer
3
 
4
+ # Hugging Face model repository
5
+ model_repo = "mradermacher/Qwen2-2B-RepleteCoder-DHM-GGUF"
6
 
7
+ # Find files containing 'Q2_K'
8
+ def find_q2_k_files(repo_id):
9
+ files = hf_hub_list(repo_id)
10
+ q2_k_files = [file for file in files if "Q2_K" in file.filename and file.filename.endswith(".gguf")]
 
 
 
11
  if not q2_k_files:
12
+ raise ValueError(f"No files containing 'Q2_K' found in the repository {repo_id}.")
13
+ return q2_k_files
14
+
15
+ # Download and load the desired model
16
+ def load_q2_k_model(repo_id):
17
+ q2_k_files = find_q2_k_files(repo_id)
18
+ # For simplicity, load the first matching file
19
+ chosen_file = q2_k_files[0]
20
+ print(f"Loading model from: {chosen_file.filename}")
21
+ model_path = hf_hub_download(repo_id, chosen_file.filename)
22
  model = AutoModel.from_pretrained(model_path)
23
  tokenizer = AutoTokenizer.from_pretrained(model_path)
24
  return model, tokenizer
25
 
26
  # Initialize the model
27
+ model, tokenizer = load_q2_k_model(model_repo)