Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,7 +9,10 @@ from pathlib import Path
|
|
| 9 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 10 |
from peft import PeftModel
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
| 13 |
HF_TOKEN = os.environ.get("HF_TOKEN") #get HF_TOKEN
|
| 14 |
login(token=HF_TOKEN)
|
| 15 |
|
|
@@ -62,23 +65,35 @@ repo_dir = snapshot_download(
|
|
| 62 |
repo_id=REPO_ID,
|
| 63 |
repo_type=REPO_TYPE,
|
| 64 |
token=HF_TOKEN,
|
| 65 |
-
cache_dir="private_space_cache"
|
|
|
|
| 66 |
)
|
| 67 |
|
| 68 |
# The fine-tuned model is located in "fine_tuned_llama3" inside the Space
|
| 69 |
fine_tuned_model_path = os.path.join(repo_dir, "fine_tuned_llama3")
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
# Verify the model path
|
| 72 |
if not os.path.exists(fine_tuned_model_path):
|
| 73 |
raise FileNotFoundError(f"Fine-tuned model not found at {fine_tuned_model_path}")
|
| 74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
# Add repo directory to sys.path
|
| 76 |
sys.path.append(repo_dir)
|
| 77 |
|
| 78 |
# Load the base model
|
| 79 |
base_model = AutoModelForCausalLM.from_pretrained(
|
| 80 |
"meta-llama/Meta-Llama-3-8B",
|
| 81 |
-
token=
|
| 82 |
)
|
| 83 |
|
| 84 |
# Load fine-tuned adapter (PEFT)
|
|
|
|
| 9 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 10 |
from peft import PeftModel
|
| 11 |
|
| 12 |
+
|
| 13 |
+
HF_TOKEN_LLAMA = os.environ.get("HF_TOKEN_LLAMA")
|
| 14 |
+
login(token=HF_TOKEN_LLAMA)
|
| 15 |
+
|
| 16 |
HF_TOKEN = os.environ.get("HF_TOKEN") #get HF_TOKEN
|
| 17 |
login(token=HF_TOKEN)
|
| 18 |
|
|
|
|
| 65 |
repo_id=REPO_ID,
|
| 66 |
repo_type=REPO_TYPE,
|
| 67 |
token=HF_TOKEN,
|
| 68 |
+
cache_dir="private_space_cache",
|
| 69 |
+
force_download=True # Forces redownload
|
| 70 |
)
|
| 71 |
|
| 72 |
# The fine-tuned model is located in "fine_tuned_llama3" inside the Space
|
| 73 |
fine_tuned_model_path = os.path.join(repo_dir, "fine_tuned_llama3")
|
| 74 |
|
| 75 |
+
|
| 76 |
+
adapter_config_path = os.path.join(fine_tuned_model_path, "adapter_config.json")
|
| 77 |
+
|
| 78 |
+
if not os.path.exists(adapter_config_path):
|
| 79 |
+
raise FileNotFoundError(f"adapter_config.json not found in {fine_tuned_model_path}. Check if the model was downloaded correctly.")
|
| 80 |
+
|
| 81 |
# Verify the model path
|
| 82 |
if not os.path.exists(fine_tuned_model_path):
|
| 83 |
raise FileNotFoundError(f"Fine-tuned model not found at {fine_tuned_model_path}")
|
| 84 |
|
| 85 |
+
|
| 86 |
+
print("Downloaded Model Path:", fine_tuned_model_path)
|
| 87 |
+
print("Files in Model Directory:", os.listdir(fine_tuned_model_path))
|
| 88 |
+
|
| 89 |
+
|
| 90 |
# Add repo directory to sys.path
|
| 91 |
sys.path.append(repo_dir)
|
| 92 |
|
| 93 |
# Load the base model
|
| 94 |
base_model = AutoModelForCausalLM.from_pretrained(
|
| 95 |
"meta-llama/Meta-Llama-3-8B",
|
| 96 |
+
token=HF_TOKEN_LLAMA
|
| 97 |
)
|
| 98 |
|
| 99 |
# Load fine-tuned adapter (PEFT)
|