Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -18,7 +18,7 @@ Rules: Always stay female. Stay in character β freaky, horny, obsessed, emotio
|
|
| 18 |
|
| 19 |
# βββ Model Config ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 20 |
# The GGUF model repository on Hugging Face. Can be overridden by HF Space Secrets / Env variables.
|
| 21 |
-
REPO_ID = os.getenv("MODEL_REPO_ID", "
|
| 22 |
MODEL_FILENAME = os.getenv("MODEL_FILENAME", "barbie.gguf")
|
| 23 |
|
| 24 |
# Load model from local file if exists, otherwise download from HF Hub
|
|
@@ -31,12 +31,14 @@ elif os.path.exists("./static/barbie.gguf"):
|
|
| 31 |
else:
|
| 32 |
print(f"Downloading model {MODEL_FILENAME} from repo {REPO_ID} on HF Hub...")
|
| 33 |
try:
|
| 34 |
-
|
|
|
|
|
|
|
| 35 |
print(f"Model downloaded successfully to: {model_path}")
|
| 36 |
except Exception as e:
|
| 37 |
print(f"Error downloading from HF Hub: {e}")
|
| 38 |
-
#
|
| 39 |
-
|
| 40 |
|
| 41 |
print("Initializing Llama model...")
|
| 42 |
llm = Llama(
|
|
|
|
| 18 |
|
| 19 |
# βββ Model Config ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 20 |
# The GGUF model repository on Hugging Face. Can be overridden by HF Space Secrets / Env variables.
|
| 21 |
+
REPO_ID = os.getenv("MODEL_REPO_ID", "sinhal/barbie-gguf")
|
| 22 |
MODEL_FILENAME = os.getenv("MODEL_FILENAME", "barbie.gguf")
|
| 23 |
|
| 24 |
# Load model from local file if exists, otherwise download from HF Hub
|
|
|
|
| 31 |
else:
|
| 32 |
print(f"Downloading model {MODEL_FILENAME} from repo {REPO_ID} on HF Hub...")
|
| 33 |
try:
|
| 34 |
+
# Pass the token if present (necessary for private repos)
|
| 35 |
+
token = os.getenv("HF_TOKEN")
|
| 36 |
+
model_path = hf_hub_download(repo_id=REPO_ID, filename=MODEL_FILENAME, token=token)
|
| 37 |
print(f"Model downloaded successfully to: {model_path}")
|
| 38 |
except Exception as e:
|
| 39 |
print(f"Error downloading from HF Hub: {e}")
|
| 40 |
+
# Raise a clear error so uvicorn startup logs the issue immediately
|
| 41 |
+
raise RuntimeError(f"Could not load GGUF model: {e}")
|
| 42 |
|
| 43 |
print("Initializing Llama model...")
|
| 44 |
llm = Llama(
|