Spaces:
Paused
Paused
| # �� Copilot �ͦ� | |
| # Hugging Face Spaces �t�m�]�w | |
| import os | |
| import warnings | |
| # �]�w�����ܼơA�u�� Hugging Face Spaces �B�� | |
| os.environ['TOKENIZERS_PARALLELISM'] = 'false' | |
| os.environ['HF_HUB_DISABLE_PROGRESS_BARS'] = '1' | |
| # �����Y��ĵ�i | |
| warnings.filterwarnings('ignore', category=UserWarning) | |
| warnings.filterwarnings('ignore', category=FutureWarning) | |
| # Hugging Face Spaces �S�w�]�w | |
| HF_SPACES_CONFIG = { | |
| 'max_sample_size': 100, # ����˥��ƶq�קK�W�� | |
| 'enable_hf_models': True, # �w�]�ҥ� HF �ҫ� | |
| 'timeout': 60, # 60���W�� | |
| 'model_cache_dir': '/tmp/hf_cache', # �ҫ��֨��ؿ� | |
| } | |
| def is_running_on_spaces(): | |
| """�ˬd�O�_�B��b Hugging Face Spaces �W""" | |
| return os.getenv('SPACE_ID') is not None | |
| def get_spaces_config(): | |
| """��� Spaces �t�m""" | |
| return HF_SPACES_CONFIG | |
| def setup_for_spaces(): | |
| """�� Spaces ���Ҷi��]�w""" | |
| if is_running_on_spaces(): | |
| print("? Running on Hugging Face Spaces") | |
| # �]�w�֨��ؿ� | |
| cache_dir = HF_SPACES_CONFIG['model_cache_dir'] | |
| if not os.path.exists(cache_dir): | |
| os.makedirs(cache_dir, exist_ok=True) | |
| # �]�w transformers �֨� | |
| os.environ['TRANSFORMERS_CACHE'] = cache_dir | |
| os.environ['HF_HOME'] = cache_dir | |
| else: | |
| print("? Running locally") | |
| # �۰ʰ���]�w | |
| setup_for_spaces() |