developer-lunark commited on
Commit
8b3427e
Β·
verified Β·
1 Parent(s): bb1d240

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +47 -93
app.py CHANGED
@@ -1,100 +1,54 @@
1
  #!/usr/bin/env python3
2
- """KAIdol A/B Test Arena - Gradio App"""
3
-
4
- import os
5
- import sys
6
-
7
- # ν˜„μž¬ 디렉토리λ₯Ό path에 μΆ”κ°€
8
- sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
9
 
10
  import gradio as gr
11
 
12
- from config import get_config
13
- from ui.arena_tab import create_arena_tab
14
- from ui.chat_tab import create_chat_tab
15
- from ui.leaderboard_tab import create_leaderboard_tab
16
- from ui.history_tab import create_history_tab
17
-
18
-
19
- def create_app():
20
- """Gradio μ•± 생성"""
21
-
22
- config = get_config()
23
- use_mock = config["model"]["use_mock"]
24
-
25
- # λͺ¨λΈ λ§€λ‹ˆμ € (Mock λͺ¨λ“œκ°€ 아닐 λ•Œλ§Œ λ‘œλ“œ)
26
- model_manager = None
27
- if not use_mock:
28
- try:
29
- from models import get_model_manager
30
- model_manager = get_model_manager(
31
- max_cached_models=config["model"]["max_cached_models"],
32
- use_4bit=config["model"]["use_4bit"],
33
- )
34
- except Exception as e:
35
- print(f"Warning: Could not load model manager: {e}")
36
- print("Running in mock mode.")
37
- use_mock = True
38
-
39
- # CSS μŠ€νƒ€μΌ
40
- css = """
41
- .response-box { min-height: 200px; }
42
- .thinking-box { background-color: #f5f5f5; padding: 10px; border-radius: 5px; }
43
- .vote-button { min-width: 100px; }
44
- .gr-button-primary { background-color: #6366f1 !important; }
45
- """
46
-
47
- # Gradio Blocks
48
- with gr.Blocks(
49
- title=config["app"]["title"],
50
- theme=gr.themes.Soft(),
51
- css=css,
52
- ) as demo:
53
-
54
- gr.Markdown(f"# {config['app']['title']}")
55
- gr.Markdown(config["app"]["description"])
56
-
57
- if use_mock:
58
- gr.Markdown("**Mock λͺ¨λ“œ**: μ‹€μ œ λͺ¨λΈ 없이 ν…ŒμŠ€νŠΈ 응닡을 μƒμ„±ν•©λ‹ˆλ‹€.")
59
-
60
- with gr.Tabs():
61
- # A/B Arena νƒ­
62
- with gr.Tab("A/B Arena"):
63
- create_arena_tab(
64
- model_manager=model_manager,
65
- use_mock=use_mock,
66
- )
67
-
68
- # Single Chat νƒ­
69
- with gr.Tab("Single Chat"):
70
- create_chat_tab(
71
- model_manager=model_manager,
72
- use_mock=use_mock,
73
- )
74
-
75
- # Leaderboard νƒ­
76
- with gr.Tab("Leaderboard"):
77
- refresh_leaderboard = create_leaderboard_tab()
78
-
79
- # History νƒ­
80
- with gr.Tab("History"):
81
- refresh_history = create_history_tab()
82
-
83
- return demo
84
-
85
-
86
- def main():
87
- """메인 ν•¨μˆ˜"""
88
- # ν™˜κ²½ λ³€μˆ˜λ‘œ Mock λͺ¨λ“œ κ°•μ œ μ„€μ • κ°€λŠ₯
89
- # USE_MOCK=true python app.py
90
-
91
- demo = create_app()
92
- demo.launch(
93
- server_name="0.0.0.0",
94
- server_port=7860,
95
- share=False,
96
  )
97
 
98
-
99
  if __name__ == "__main__":
100
- main()
 
1
  #!/usr/bin/env python3
2
+ """KAIdol A/B Test Arena - Simple Version"""
 
 
 
 
 
 
3
 
4
  import gradio as gr
5
 
6
+ def chat_response(message, character):
7
+ """Mock 응닡 생성"""
8
+ thinking = f"<think>{character}의 μž…μž₯μ—μ„œ 생각해보면... 이 λ©”μ‹œμ§€μ— μ–΄λ–»κ²Œ λ°˜μ‘ν•΄μ•Ό ν• κΉŒ?</think>"
9
+ response = f"μ•ˆλ…•~ λ°˜κ°€μ›Œ! λ‚˜λŠ” {character}μ•Ό~"
10
+ return f"{thinking}\n\n{response}"
11
+
12
+ # 캐릭터 λͺ©λ‘
13
+ CHARACTERS = ["κ°•μœ¨", "μ„œμ΄μ•ˆ", "이지후", "μ°¨λ„ν•˜", "졜민"]
14
+
15
+ # λͺ¨λΈ λͺ©λ‘
16
+ MODELS = [
17
+ "hyperclovax-32b-dpo-v5",
18
+ "qwen2.5-14b-dpo-v5",
19
+ "qwen2.5-7b-dpo-v5",
20
+ "exaone-7.8b-dpo-v5",
21
+ ]
22
+
23
+ with gr.Blocks(title="KAIdol A/B Test Arena") as demo:
24
+ gr.Markdown("# KAIdol A/B Test Arena")
25
+ gr.Markdown("K-pop μ•„μ΄λŒ λ‘€ν”Œλ ˆμ΄ λͺ¨λΈ A/B 비ꡐ 평가")
26
+ gr.Markdown("**Mock λͺ¨λ“œ**: μ‹€μ œ λͺ¨λΈ 없이 ν…ŒμŠ€νŠΈ 응닡을 μƒμ„±ν•©λ‹ˆλ‹€.")
27
+
28
+ with gr.Row():
29
+ character = gr.Dropdown(choices=CHARACTERS, value="κ°•μœ¨", label="캐릭터")
30
+ model_a = gr.Dropdown(choices=MODELS, value=MODELS[0], label="Model A")
31
+ model_b = gr.Dropdown(choices=MODELS, value=MODELS[1], label="Model B")
32
+
33
+ with gr.Row():
34
+ with gr.Column():
35
+ gr.Markdown("### Model A")
36
+ response_a = gr.Textbox(label="응닡", lines=5)
37
+ with gr.Column():
38
+ gr.Markdown("### Model B")
39
+ response_b = gr.Textbox(label="응닡", lines=5)
40
+
41
+ user_input = gr.Textbox(label="λ©”μ‹œμ§€", placeholder="μ•„μ΄λŒμ—κ²Œ λ©”μ‹œμ§€λ₯Ό λ³΄λ‚΄μ„Έμš”...")
42
+ submit_btn = gr.Button("전솑", variant="primary")
43
+
44
+ def generate(msg, char, ma, mb):
45
+ return chat_response(msg, char), chat_response(msg, char)
46
+
47
+ submit_btn.click(
48
+ fn=generate,
49
+ inputs=[user_input, character, model_a, model_b],
50
+ outputs=[response_a, response_b]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  )
52
 
 
53
  if __name__ == "__main__":
54
+ demo.launch(server_name="0.0.0.0", server_port=7860)