Spaces:
Sleeping
Sleeping
| """ | |
| Hugging Face Spaces 入口文件 | |
| 这个文件是 Hugging Face Spaces 的标准入口点 | |
| """ | |
| import os | |
| import sys | |
| # 设置工作目录 | |
| script_dir = os.path.dirname(os.path.abspath(__file__)) | |
| os.chdir(script_dir) | |
| # 添加 LightEnv 目录到 Python 路径 | |
| lightenv_path = os.path.join(script_dir, "LightEnv") | |
| if os.path.exists(lightenv_path): | |
| sys.path.insert(0, lightenv_path) | |
| # 修复 huggingface_hub 兼容性(必须在导入 gradio 之前) | |
| def _fix_huggingface_hub(): | |
| """修复 huggingface_hub 兼容性问题""" | |
| try: | |
| import huggingface_hub | |
| if not hasattr(huggingface_hub, 'HfFolder'): | |
| class HfFolder: | |
| def save_token(token): | |
| pass | |
| def get_token(): | |
| return None | |
| def get_token_path(): | |
| return None | |
| huggingface_hub.HfFolder = HfFolder | |
| if hasattr(huggingface_hub, '__all__'): | |
| if 'HfFolder' not in huggingface_hub.__all__: | |
| huggingface_hub.__all__.append('HfFolder') | |
| except Exception: | |
| pass | |
| _fix_huggingface_hub() | |
| # 导入 GUI-Light 模块 | |
| # 由于文件名包含连字符,需要使用 importlib | |
| import importlib.util | |
| gui_light_path = os.path.join(script_dir, "GUI-Light.py") | |
| spec = importlib.util.spec_from_file_location("gui_light", gui_light_path) | |
| gui_light = importlib.util.module_from_spec(spec) | |
| sys.modules["gui_light"] = gui_light | |
| spec.loader.exec_module(gui_light) | |
| # 加载测试数据 | |
| gui_light.load_test_data() | |
| # 创建 Gradio 应用 | |
| demo = gui_light.create_interface() | |
| # Hugging Face Spaces 会自动调用 demo.launch() | |
| # 但为了确保兼容性,我们也可以显式调用 | |
| if __name__ == "__main__": | |
| demo.launch() | |