Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
8640a78
1
Parent(s):
042f856
Fix Zero GPU compatibility and add conditional support
Browse files- Add conditional import for spaces module
- Separate implementation function from decorated function
- Apply Zero GPU decorator only when spaces is available
- Add models list to README.md for HF Spaces
- This allows the app to run both with and without GPU support
README.md
CHANGED
@@ -8,6 +8,10 @@ sdk_version: 5.34.2
|
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: mit
|
|
|
|
|
|
|
|
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: mit
|
11 |
+
models:
|
12 |
+
- PascalNotin/Tranception_Small
|
13 |
+
- PascalNotin/Tranception_Medium
|
14 |
+
- PascalNotin/Tranception_Large
|
15 |
---
|
16 |
|
17 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
CHANGED
@@ -17,7 +17,14 @@ import zipfile
|
|
17 |
import shutil
|
18 |
import uuid
|
19 |
import gc
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
# Add current directory to path
|
23 |
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
@@ -225,8 +232,7 @@ def get_mutated_protein(sequence,mutant):
|
|
225 |
mutated_sequence[int(mutant[1:-1])-1]=mutant[-1]
|
226 |
return ''.join(mutated_sequence)
|
227 |
|
228 |
-
|
229 |
-
def score_and_create_matrix_all_singles(sequence,mutation_range_start=None,mutation_range_end=None,model_type="Large",scoring_mirror=False,batch_size_inference=20,max_number_positions_per_heatmap=50,num_workers=0,AA_vocab=AA_vocab):
|
230 |
# Clean up old files periodically
|
231 |
cleanup_old_files()
|
232 |
|
@@ -328,6 +334,12 @@ def score_and_create_matrix_all_singles(sequence,mutation_range_start=None,mutat
|
|
328 |
if torch.cuda.is_available():
|
329 |
torch.cuda.empty_cache()
|
330 |
|
|
|
|
|
|
|
|
|
|
|
|
|
331 |
def extract_sequence(protein_id, taxon, sequence):
|
332 |
return sequence
|
333 |
|
|
|
17 |
import shutil
|
18 |
import uuid
|
19 |
import gc
|
20 |
+
|
21 |
+
# Try to import spaces for Zero GPU support
|
22 |
+
try:
|
23 |
+
import spaces
|
24 |
+
SPACES_AVAILABLE = True
|
25 |
+
except ImportError:
|
26 |
+
SPACES_AVAILABLE = False
|
27 |
+
print("Warning: spaces module not available. Running without Zero GPU support.")
|
28 |
|
29 |
# Add current directory to path
|
30 |
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
|
232 |
mutated_sequence[int(mutant[1:-1])-1]=mutant[-1]
|
233 |
return ''.join(mutated_sequence)
|
234 |
|
235 |
+
def score_and_create_matrix_all_singles_impl(sequence,mutation_range_start=None,mutation_range_end=None,model_type="Large",scoring_mirror=False,batch_size_inference=20,max_number_positions_per_heatmap=50,num_workers=0,AA_vocab=AA_vocab):
|
|
|
236 |
# Clean up old files periodically
|
237 |
cleanup_old_files()
|
238 |
|
|
|
334 |
if torch.cuda.is_available():
|
335 |
torch.cuda.empty_cache()
|
336 |
|
337 |
+
# Apply Zero GPU decorator if available
|
338 |
+
if SPACES_AVAILABLE:
|
339 |
+
score_and_create_matrix_all_singles = spaces.GPU(duration=300)(score_and_create_matrix_all_singles_impl)
|
340 |
+
else:
|
341 |
+
score_and_create_matrix_all_singles = score_and_create_matrix_all_singles_impl
|
342 |
+
|
343 |
def extract_sequence(protein_id, taxon, sequence):
|
344 |
return sequence
|
345 |
|