Spaces:
Sleeping
Sleeping
File size: 743 Bytes
5173b8d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# spaces_optimizer.py - Spaces optimizasyonu
import gc
import psutil
import threading
from functools import lru_cache
class SpacesOptimizer:
"""Hugging Face Spaces için optimizasyon sınıfı"""
def __init__(self):
self.memory_limit = 16 * 1024 * 1024 * 1024 # 16GB
self.optimize_memory()
def optimize_memory(self):
"""Bellek optimizasyonu"""
# Garbage collection
gc.collect()
if torch.cuda.is_available():
torch.cuda.empty_cache()
# Thread sayısını optimize et
torch.set_num_threads(2)
@lru_cache(maxsize=1)
def load_model_cached(self):
"""Modeli cache'le"""
return ProfessionalGeoReferencingSystem() |