File size: 3,083 Bytes
5e8f045
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87eec44
 
5e8f045
15cfa55
5e8f045
 
 
 
 
4a43fed
 
5e8f045
 
 
 
 
 
 
 
4a43fed
 
 
 
 
 
 
5e8f045
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
"""
Ko-FreshQA Leaderboard 메인 μ• ν”Œλ¦¬μΌ€μ΄μ…˜

Gradio 기반의 μ›Ή μΈν„°νŽ˜μ΄μŠ€λ₯Ό μ œκ³΅ν•©λ‹ˆλ‹€.
"""

import os
import gradio as gr
from config import Config
from ui.leaderboard_tab import create_leaderboard_tab
from ui.submission_tab import create_submission_tab
from ui.dataset_tab import create_dataset_tab


def load_css():
    """CSS 파일 λ‘œλ“œ"""
    current_dir = os.path.dirname(os.path.abspath(__file__))
    css_path = os.path.join(current_dir, 'ui', 'styles.css')
    
    try:
        with open(css_path, 'r', encoding='utf-8') as f:
            return f.read()
    except FileNotFoundError:
        print("⚠️ CSS νŒŒμΌμ„ 찾을 수 μ—†μŠ΅λ‹ˆλ‹€: {css_path}")
        raise FileNotFoundError(f"CSS νŒŒμΌμ„ 찾을 수 μ—†μŠ΅λ‹ˆλ‹€: {css_path}")


def create_interface():
    """메인 μΈν„°νŽ˜μ΄μŠ€ 생성"""
    
    css_content = load_css()
    
    with gr.Blocks(
        title="Ko-FreshQA Leaderboard",
        theme=gr.themes.Soft()
    ) as app:
        gr.HTML(f"<style>{css_content}</style>")
        gr.Markdown("# Ko-FreshQA Leaderboard")

        with gr.Tabs():
            # λ¦¬λ”λ³΄λ“œ νƒ­
            with gr.Tab("πŸ† λ¦¬λ”λ³΄λ“œ"):
                # βœ… λ¦¬λ”λ³΄λ“œ μ»΄ν¬λ„ŒνŠΈμ™€ μƒˆλ‘œκ³ μΉ¨ ν•¨μˆ˜ λ°›μ•„μ˜€κΈ°
                relaxed_table, strict_table, refresh_leaderboard = create_leaderboard_tab()
            
            # 제좜 및 평가 νƒ­
            with gr.Tab("πŸ“€ 제좜 및 평가"):
                create_submission_tab()
            
            # 데이터셋 λ‹€μš΄λ‘œλ“œ νƒ­
            with gr.Tab("πŸ’Ύ 데이터셋"):
                create_dataset_tab()
        
        # βœ… 앱이 λ‘œλ“œλ  λ•Œλ§ˆλ‹€(μ‚¬μš©μžκ°€ νŽ˜μ΄μ§€ 처음 μ—΄ λ•Œλ§ˆλ‹€) ν•œ 번 μžλ™μœΌλ‘œ μƒˆλ‘œκ³ μΉ¨
        app.load(
            fn=refresh_leaderboard,
            inputs=None,
            outputs=[relaxed_table, strict_table],
        )
    
    return app


def main():
    """메인 μ‹€ν–‰ ν•¨μˆ˜"""
    print("πŸ‡°πŸ‡· ν•œκ΅­μ–΄ FreshQA λ¦¬λ”λ³΄λ“œ μ‹œμž‘ 쀑...")
    print("πŸ“‹ λ¦¬λ”λ³΄λ“œ μ œμΆœμ„ μœ„ν•΄μ„œλŠ” 'πŸ“€ 제좜 및 평가' 탭을 μ‚¬μš©ν•˜μ„Έμš”.")
    
    # ν•„μˆ˜ μ„€μ • 검증
    try:
        Config.validate_required_configs()
        print("βœ… ν•„μˆ˜ μ„€μ • 검증 μ™„λ£Œ")
    except ValueError as e:
        print(f"❌ μ„€μ • 였λ₯˜: {e}")
        import sys
        sys.exit(1)
    
    app = create_interface()
    
    # Hugging Face Spaces ν™˜κ²½ 감지
    is_huggingface_spaces = Config.IS_HUGGINGFACE_SPACES
    
    if is_huggingface_spaces:
        print("πŸš€ Hugging Face Spaces ν™˜κ²½μ—μ„œ μ‹€ν–‰ 쀑...")
        app.launch(
            server_name="0.0.0.0",
            server_port=7860,
            share=False,
            debug=False,
            show_error=True
        )
    else:
        print("πŸ’» 둜컬 ν™˜κ²½μ—μ„œ μ‹€ν–‰ 쀑...")
        app.launch(
            server_name="127.0.0.1",
            server_port=7860,
            share=False,
            debug=True,
            show_error=True
        )


if __name__ == "__main__":
    main()