Spaces:
Build error
Build error
Upload folder using huggingface_hub
Browse files
.github/workflows/deploy-to-hf-spaces.yml
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: Deploy to HuggingFace Spaces
|
| 2 |
+
|
| 3 |
+
on:
|
| 4 |
+
push:
|
| 5 |
+
branches:
|
| 6 |
+
- main
|
| 7 |
+
|
| 8 |
+
jobs:
|
| 9 |
+
deploy:
|
| 10 |
+
runs-on: ubuntu-latest
|
| 11 |
+
steps:
|
| 12 |
+
- name: Checkout repository
|
| 13 |
+
uses: actions/checkout@v4
|
| 14 |
+
with:
|
| 15 |
+
fetch-depth: 0
|
| 16 |
+
lfs: true
|
| 17 |
+
|
| 18 |
+
- name: Set up Python
|
| 19 |
+
uses: actions/setup-python@v5
|
| 20 |
+
with:
|
| 21 |
+
python-version: '3.10'
|
| 22 |
+
|
| 23 |
+
- name: Install huggingface_hub
|
| 24 |
+
run: pip install huggingface_hub
|
| 25 |
+
|
| 26 |
+
- name: Deploy to HuggingFace Spaces
|
| 27 |
+
env:
|
| 28 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
| 29 |
+
run: |
|
| 30 |
+
python - <<EOF
|
| 31 |
+
from huggingface_hub import HfApi
|
| 32 |
+
import os
|
| 33 |
+
|
| 34 |
+
api = HfApi(token=os.environ['HF_TOKEN'])
|
| 35 |
+
|
| 36 |
+
# Upload files to the Space
|
| 37 |
+
api.upload_folder(
|
| 38 |
+
folder_path='.',
|
| 39 |
+
repo_id='eduardofarina/MedGemma1.5ReportGenerator',
|
| 40 |
+
repo_type='space',
|
| 41 |
+
ignore_patterns=[
|
| 42 |
+
'models/*',
|
| 43 |
+
'.git/*',
|
| 44 |
+
'.github/*',
|
| 45 |
+
'__pycache__/*',
|
| 46 |
+
'*.pyc',
|
| 47 |
+
'.env',
|
| 48 |
+
'environment.yml',
|
| 49 |
+
'setup*.bat',
|
| 50 |
+
'setup*.sh',
|
| 51 |
+
'check_gpu.py',
|
| 52 |
+
'download_model.py',
|
| 53 |
+
'dicom_utils.py',
|
| 54 |
+
],
|
| 55 |
+
)
|
| 56 |
+
print('Deployment to HuggingFace Spaces complete!')
|
| 57 |
+
EOF
|
model_handler.py
CHANGED
|
@@ -86,10 +86,10 @@ class MedGemmaHandler:
|
|
| 86 |
|
| 87 |
# Load model with proper device configuration
|
| 88 |
if self.device == "cuda" and torch.cuda.is_available():
|
| 89 |
-
print("Loading model on GPU with
|
| 90 |
self.model = AutoModelForImageTextToText.from_pretrained(
|
| 91 |
self.model_id,
|
| 92 |
-
torch_dtype=torch.
|
| 93 |
device_map="cuda",
|
| 94 |
token=hf_token,
|
| 95 |
)
|
|
@@ -139,7 +139,7 @@ class MedGemmaHandler:
|
|
| 139 |
|
| 140 |
# Move to device with proper dtype
|
| 141 |
if self.device == "cuda":
|
| 142 |
-
inputs = inputs.to(self.model.device, dtype=torch.
|
| 143 |
else:
|
| 144 |
inputs = inputs.to(self.model.device)
|
| 145 |
|
|
|
|
| 86 |
|
| 87 |
# Load model with proper device configuration
|
| 88 |
if self.device == "cuda" and torch.cuda.is_available():
|
| 89 |
+
print("Loading model on GPU with float16...")
|
| 90 |
self.model = AutoModelForImageTextToText.from_pretrained(
|
| 91 |
self.model_id,
|
| 92 |
+
torch_dtype=torch.float16,
|
| 93 |
device_map="cuda",
|
| 94 |
token=hf_token,
|
| 95 |
)
|
|
|
|
| 139 |
|
| 140 |
# Move to device with proper dtype
|
| 141 |
if self.device == "cuda":
|
| 142 |
+
inputs = inputs.to(self.model.device, dtype=torch.float16)
|
| 143 |
else:
|
| 144 |
inputs = inputs.to(self.model.device)
|
| 145 |
|