KeivanR commited on
Commit
d394f04
·
1 Parent(s): b28c699

token in app

Browse files
Files changed (2) hide show
  1. Dockerfile +0 -9
  2. app.py +16 -0
Dockerfile CHANGED
@@ -29,15 +29,6 @@ RUN pip install --no-cache-dir \
29
  torchvision==0.16.2+cu121 \
30
  --extra-index-url https://download.pytorch.org/whl/cu121
31
 
32
- # Set up Hugging Face authentication (use a build ARG for the token)
33
- # ARG HF_TOKEN
34
- # RUN python3 -c "from huggingface_hub import login; login(token='$HF_TOKEN')"
35
-
36
- # Test model loading (use absolute import path)
37
- RUN python3 -c "from qwen_classifier.model import QwenClassifier; \
38
- QwenClassifier.from_pretrained('KeivanR/Qwen2.5-1.5B-Instruct-MLB-clf_lora-1743189446'); \
39
- print('Model loaded successfully')"
40
-
41
  # Run FastAPI app
42
  EXPOSE 7860
43
  CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
29
  torchvision==0.16.2+cu121 \
30
  --extra-index-url https://download.pytorch.org/whl/cu121
31
 
 
 
 
 
 
 
 
 
 
32
  # Run FastAPI app
33
  EXPOSE 7860
34
  CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py CHANGED
@@ -1,6 +1,9 @@
1
  from fastapi import FastAPI
2
  from qwen_classifier.predict import predict_single # Your existing function
3
  import torch
 
 
 
4
 
5
  app = FastAPI(title="Qwen Classifier")
6
 
@@ -8,6 +11,19 @@ app = FastAPI(title="Qwen Classifier")
8
  async def load_model():
9
  # Warm up GPU
10
  torch.zeros(1).cuda()
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  @app.post("/predict")
13
  async def predict(text: str):
 
1
  from fastapi import FastAPI
2
  from qwen_classifier.predict import predict_single # Your existing function
3
  import torch
4
+ from huggingface_hub import login
5
+ from qwen_classifier.model import QwenClassifier
6
+ import os
7
 
8
  app = FastAPI(title="Qwen Classifier")
9
 
 
11
  async def load_model():
12
  # Warm up GPU
13
  torch.zeros(1).cuda()
14
+ # Read HF_TOKEN from Hugging Face Space secrets
15
+ hf_token = os.getenv("HF_TOKEN")
16
+ if not hf_token:
17
+ raise ValueError("HF_TOKEN not found in environment variables")
18
+
19
+ # Authenticate
20
+ login(token=hf_token)
21
+
22
+ # Load model (will cache in /home/user/.cache/huggingface)
23
+ app.state.model = QwenClassifier.from_pretrained(
24
+ 'KeivanR/Qwen2.5-1.5B-Instruct-MLB-clf_lora-1743189446'
25
+ )
26
+ print("Model loaded successfully!")
27
 
28
  @app.post("/predict")
29
  async def predict(text: str):