Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,18 +22,33 @@ print("=" * 50)
|
|
| 22 |
# ------------------------------------------------------
|
| 23 |
# πΉ STEP 1: Authentication for HF Spaces
|
| 24 |
# ------------------------------------------------------
|
| 25 |
-
|
|
|
|
| 26 |
|
| 27 |
-
if hf_token:
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
# ------------------------------------------------------
|
| 34 |
# πΉ STEP 2: Load model and tokenizer
|
| 35 |
# ------------------------------------------------------
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
print("π Loading tokenizer...")
|
| 39 |
try:
|
|
|
|
| 22 |
# ------------------------------------------------------
|
| 23 |
# πΉ STEP 1: Authentication for HF Spaces
|
| 24 |
# ------------------------------------------------------
|
| 25 |
+
# Check both possible token names (order matters!)
|
| 26 |
+
hf_token = os.getenv("HUGGINGFACE_HUB_TOKEN") or os.getenv("HF_TOKEN")
|
| 27 |
|
| 28 |
+
if not hf_token:
|
| 29 |
+
raise ValueError(
|
| 30 |
+
"β No token found!\n"
|
| 31 |
+
"Please add your Hugging Face token in Space Settings β Repository secrets.\n"
|
| 32 |
+
"Name it either: HUGGINGFACE_HUB_TOKEN or HF_TOKEN\n"
|
| 33 |
+
"Create a token at: https://huggingface.co/settings/tokens"
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
print(f"β
HF Token found (length: {len(hf_token)})")
|
| 37 |
+
print("π Logging in to Hugging Face...")
|
| 38 |
+
login(token=hf_token)
|
| 39 |
+
print("β
Login successful!")
|
| 40 |
|
| 41 |
# ------------------------------------------------------
|
| 42 |
# πΉ STEP 2: Load model and tokenizer
|
| 43 |
# ------------------------------------------------------
|
| 44 |
+
# Option 1: MedGemma (requires access request)
|
| 45 |
+
# model_id = "google/medgemma-27b-text-it"
|
| 46 |
+
|
| 47 |
+
# Option 2: Regular Gemma (no access needed, works immediately)
|
| 48 |
+
model_id = "google/gemma-2-9b-it" # Smaller, faster, no access required
|
| 49 |
+
|
| 50 |
+
# Option 3: Mistral (medical fine-tuned alternative)
|
| 51 |
+
# model_id = "mistralai/Mistral-7B-Instruct-v0.3"
|
| 52 |
|
| 53 |
print("π Loading tokenizer...")
|
| 54 |
try:
|