Spaces:
Runtime error
Runtime error
Austin Stockbridge
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,24 +1,27 @@
|
|
| 1 |
-
import
|
| 2 |
from transformers import AutoModel, AutoTokenizer
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
def
|
| 9 |
-
|
| 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
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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(
|
|
|
|
| 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)
|