File size: 1,852 Bytes
9b5deef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""
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:
                @staticmethod
                def save_token(token):
                    pass
                @staticmethod
                def get_token():
                    return None
                @staticmethod
                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()