Spaces:
Running
on
Zero
Running
on
Zero
playground
Browse files- app.py +4 -1
- docs/leaderboard_header.md +2 -3
- indiebot_arena/ui/battle.py +8 -7
- indiebot_arena/ui/playground.py +100 -0
app.py
CHANGED
@@ -5,6 +5,7 @@ from indiebot_arena.dao.mongo_dao import MongoDAO
|
|
5 |
from indiebot_arena.service.bootstrap_service import BootstrapService
|
6 |
from indiebot_arena.ui.battle import battle_content
|
7 |
from indiebot_arena.ui.leaderboard import leaderboard_content
|
|
|
8 |
from indiebot_arena.ui.registration import registration_content
|
9 |
|
10 |
dao = MongoDAO(MONGO_DB_URI, MONGO_DB_NAME)
|
@@ -15,10 +16,12 @@ with gr.Blocks(theme=gr.themes.Citrus(primary_hue="sky"), css_paths="style.css")
|
|
15 |
with gr.Tabs():
|
16 |
with gr.TabItem("🏆 リーダーボード"):
|
17 |
leaderboard_content(dao, LANGUAGE)
|
18 |
-
with gr.TabItem("⚔️
|
19 |
battle_content(dao, LANGUAGE)
|
20 |
with gr.TabItem("📚️ モデルの登録"):
|
21 |
registration_content(dao, LANGUAGE)
|
|
|
|
|
22 |
|
23 |
if __name__=="__main__":
|
24 |
demo.queue(max_size=20).launch()
|
|
|
5 |
from indiebot_arena.service.bootstrap_service import BootstrapService
|
6 |
from indiebot_arena.ui.battle import battle_content
|
7 |
from indiebot_arena.ui.leaderboard import leaderboard_content
|
8 |
+
from indiebot_arena.ui.playground import playground_content
|
9 |
from indiebot_arena.ui.registration import registration_content
|
10 |
|
11 |
dao = MongoDAO(MONGO_DB_URI, MONGO_DB_NAME)
|
|
|
16 |
with gr.Tabs():
|
17 |
with gr.TabItem("🏆 リーダーボード"):
|
18 |
leaderboard_content(dao, LANGUAGE)
|
19 |
+
with gr.TabItem("⚔️ チャット対戦"):
|
20 |
battle_content(dao, LANGUAGE)
|
21 |
with gr.TabItem("📚️ モデルの登録"):
|
22 |
registration_content(dao, LANGUAGE)
|
23 |
+
with gr.TabItem("💬 Playground"):
|
24 |
+
playground_content(dao, LANGUAGE)
|
25 |
|
26 |
if __name__=="__main__":
|
27 |
demo.queue(max_size=20).launch()
|
docs/leaderboard_header.md
CHANGED
@@ -8,10 +8,9 @@ Chatbot Arenaにインスパイアされて開発しましたが、以下のよ
|
|
8 |
- 階級別にチャットバトルとリーダーボードがある
|
9 |
|
10 |
初期データとして、Google公式のInstruction-Tuning済みモデルを登録しています。
|
11 |
-
|
12 |
-
[モデルの登録]から自分の事後学習済みモデルを登録することも出来ます。
|
13 |
-
Google公式モデルをみんなで倒しましょう!
|
14 |
|
15 |
【更新履歴】
|
|
|
16 |
- 2025/04/03 チャットがストリーミング方式になり応答速度が向上しました。
|
17 |
- 2025/03/31 ベータ版を公開。機能は一通り完成していますが、性能をテスト中。
|
|
|
8 |
- 階級別にチャットバトルとリーダーボードがある
|
9 |
|
10 |
初期データとして、Google公式のInstruction-Tuning済みモデルを登録しています。
|
11 |
+
Google公式ITモデルをみんなで倒しましょう!
|
|
|
|
|
12 |
|
13 |
【更新履歴】
|
14 |
+
- 2025/04/09 Playground機能を追加、モデルを指定して直接チャットできます。
|
15 |
- 2025/04/03 チャットがストリーミング方式になり応答速度が向上しました。
|
16 |
- 2025/03/31 ベータ版を公開。機能は一通り完成していますが、性能をテスト中。
|
indiebot_arena/ui/battle.py
CHANGED
@@ -9,7 +9,7 @@ import spaces
|
|
9 |
import torch
|
10 |
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
|
11 |
|
12 |
-
from indiebot_arena.config import MODEL_SELECTION_MODE, MAX_INPUT_TOKEN_LENGTH, MAX_NEW_TOKENS
|
13 |
from indiebot_arena.service.arena_service import ArenaService
|
14 |
from indiebot_arena.util.cache_manager import get_free_space_gb, clear_hf_cache
|
15 |
|
@@ -63,11 +63,12 @@ def generate(chat_history: list,
|
|
63 |
yield "".join(outputs)
|
64 |
|
65 |
|
66 |
-
def update_user_message(user_message, history_a, history_b
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
|
|
71 |
|
72 |
new_history_a = history_a + [{"role": "user", "content": user_message}]
|
73 |
new_history_b = history_b + [{"role": "user", "content": user_message}]
|
@@ -214,7 +215,7 @@ def battle_content(dao, language):
|
|
214 |
next_battle_btn = gr.Button("次のバトルへ", variant="primary", interactive=False, visible=False, elem_id="next_battle_btn")
|
215 |
user_event = user_input.submit(
|
216 |
update_user_message,
|
217 |
-
inputs=[user_input, chatbot_a, chatbot_b
|
218 |
outputs=[user_input, chatbot_a, chatbot_b, weight_class_radio],
|
219 |
queue=False
|
220 |
)
|
|
|
9 |
import torch
|
10 |
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
|
11 |
|
12 |
+
from indiebot_arena.config import MODEL_SELECTION_MODE, MAX_INPUT_TOKEN_LENGTH, MAX_NEW_TOKENS, LOCAL_TESTING
|
13 |
from indiebot_arena.service.arena_service import ArenaService
|
14 |
from indiebot_arena.util.cache_manager import get_free_space_gb, clear_hf_cache
|
15 |
|
|
|
63 |
yield "".join(outputs)
|
64 |
|
65 |
|
66 |
+
def update_user_message(user_message, history_a, history_b):
|
67 |
+
if not LOCAL_TESTING:
|
68 |
+
total, _, free = get_free_space_gb("/data")
|
69 |
+
print(f"空きディスク容量: {free:.2f} GB / {total:.2f} GB")
|
70 |
+
if free < (total * 0.2):
|
71 |
+
clear_hf_cache()
|
72 |
|
73 |
new_history_a = history_a + [{"role": "user", "content": user_message}]
|
74 |
new_history_b = history_b + [{"role": "user", "content": user_message}]
|
|
|
215 |
next_battle_btn = gr.Button("次のバトルへ", variant="primary", interactive=False, visible=False, elem_id="next_battle_btn")
|
216 |
user_event = user_input.submit(
|
217 |
update_user_message,
|
218 |
+
inputs=[user_input, chatbot_a, chatbot_b],
|
219 |
outputs=[user_input, chatbot_a, chatbot_b, weight_class_radio],
|
220 |
queue=False
|
221 |
)
|
indiebot_arena/ui/playground.py
ADDED
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
from indiebot_arena.config import LOCAL_TESTING
|
6 |
+
from indiebot_arena.service.arena_service import ArenaService
|
7 |
+
from indiebot_arena.ui.battle import generate
|
8 |
+
from indiebot_arena.util.cache_manager import get_free_space_gb, clear_hf_cache
|
9 |
+
|
10 |
+
DESCRIPTION = "### 💬 Playground"
|
11 |
+
|
12 |
+
base_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
|
13 |
+
docs_path = os.path.join(base_dir, "docs", "battle_header.md")
|
14 |
+
|
15 |
+
|
16 |
+
def update_user_message(user_message, history_a):
|
17 |
+
if not LOCAL_TESTING:
|
18 |
+
total, _, free = get_free_space_gb("/data")
|
19 |
+
print(f"空きディスク容量: {free:.2f} GB / {total:.2f} GB")
|
20 |
+
if free < (total * 0.2):
|
21 |
+
clear_hf_cache()
|
22 |
+
|
23 |
+
new_history_a = history_a + [{"role": "user", "content": user_message}]
|
24 |
+
return "", new_history_a
|
25 |
+
|
26 |
+
|
27 |
+
def bot1_response(history, model_id):
|
28 |
+
history = history.copy()
|
29 |
+
history.append({"role": "assistant", "content": ""})
|
30 |
+
conv_history = history[:-1]
|
31 |
+
for text in generate(conv_history, model_id):
|
32 |
+
history[-1]["content"] = text
|
33 |
+
yield history
|
34 |
+
|
35 |
+
|
36 |
+
def playground_content(dao, language):
|
37 |
+
arena_service = ArenaService(dao)
|
38 |
+
default_weight = "U-5GB"
|
39 |
+
initial_models = arena_service.get_model_dropdown_list(language, default_weight)
|
40 |
+
initial_choices = [m["label"] for m in initial_models]
|
41 |
+
initial_value = initial_choices[0]
|
42 |
+
|
43 |
+
def fetch_model_dropdown(weight_class):
|
44 |
+
models = arena_service.get_model_dropdown_list(language, weight_class)
|
45 |
+
model_labels = [m["label"] for m in models]
|
46 |
+
update_obj_a = gr.update(choices=model_labels, value=model_labels[0])
|
47 |
+
return update_obj_a
|
48 |
+
|
49 |
+
with gr.Blocks(css="style.css") as battle_ui:
|
50 |
+
gr.Markdown(DESCRIPTION)
|
51 |
+
with open(docs_path, "r", encoding="utf-8") as f:
|
52 |
+
markdown_content = f.read()
|
53 |
+
gr.HTML(markdown_content)
|
54 |
+
weight_class_radio = gr.Radio(
|
55 |
+
choices=["U-5GB", "U-10GB"],
|
56 |
+
label="階級",
|
57 |
+
value=default_weight
|
58 |
+
)
|
59 |
+
model_dropdown_a = gr.Dropdown(
|
60 |
+
choices=initial_choices,
|
61 |
+
label="モデルを選択",
|
62 |
+
value=initial_value,
|
63 |
+
visible=True
|
64 |
+
)
|
65 |
+
chatbot_a = gr.Chatbot(label="Chatbot A", type="messages")
|
66 |
+
user_input = gr.Textbox(
|
67 |
+
placeholder="日本語でメッセージを入力...",
|
68 |
+
submit_btn=True,
|
69 |
+
show_label=False
|
70 |
+
)
|
71 |
+
user_event = user_input.submit(
|
72 |
+
update_user_message,
|
73 |
+
inputs=[user_input, chatbot_a],
|
74 |
+
outputs=[user_input, chatbot_a],
|
75 |
+
queue=False
|
76 |
+
)
|
77 |
+
user_event.then(
|
78 |
+
bot1_response,
|
79 |
+
inputs=[chatbot_a, model_dropdown_a],
|
80 |
+
outputs=[chatbot_a],
|
81 |
+
queue=True
|
82 |
+
)
|
83 |
+
weight_class_radio.change(
|
84 |
+
fn=fetch_model_dropdown,
|
85 |
+
inputs=weight_class_radio,
|
86 |
+
outputs=[model_dropdown_a]
|
87 |
+
)
|
88 |
+
weight_class_radio.change(
|
89 |
+
fn=lambda _: [],
|
90 |
+
inputs=weight_class_radio,
|
91 |
+
outputs=chatbot_a,
|
92 |
+
queue=False
|
93 |
+
)
|
94 |
+
model_dropdown_a.change(
|
95 |
+
fn=lambda _: [],
|
96 |
+
inputs=model_dropdown_a,
|
97 |
+
outputs=chatbot_a,
|
98 |
+
queue=False
|
99 |
+
)
|
100 |
+
return battle_ui
|