Spaces:
Running
on
Zero
Running
on
Zero
update
Browse files
indiebot_arena/ui/battle.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import hashlib
|
2 |
import os
|
3 |
import random
|
|
|
4 |
from collections.abc import Iterator
|
5 |
from threading import Thread
|
6 |
|
@@ -19,6 +20,11 @@ base_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
|
|
19 |
docs_path = os.path.join(base_dir, "docs", "battle_header.md")
|
20 |
|
21 |
|
|
|
|
|
|
|
|
|
|
|
22 |
@spaces.GPU(duration=30)
|
23 |
def generate(chat_history: list,
|
24 |
model_id: str,
|
@@ -80,7 +86,8 @@ def bot1_response(history, model_id):
|
|
80 |
history.append({"role": "assistant", "content": ""})
|
81 |
conv_history = history[:-1]
|
82 |
for text in generate(conv_history, model_id):
|
83 |
-
|
|
|
84 |
yield history, gr.update(interactive=True), gr.update(interactive=True)
|
85 |
|
86 |
|
@@ -89,7 +96,8 @@ def bot2_response(history, model_id):
|
|
89 |
history.append({"role": "assistant", "content": ""})
|
90 |
conv_history = history[:-1]
|
91 |
for text in generate(conv_history, model_id):
|
92 |
-
|
|
|
93 |
yield history, gr.update(interactive=True), gr.update(interactive=True)
|
94 |
|
95 |
|
|
|
1 |
import hashlib
|
2 |
import os
|
3 |
import random
|
4 |
+
import re
|
5 |
from collections.abc import Iterator
|
6 |
from threading import Thread
|
7 |
|
|
|
20 |
docs_path = os.path.join(base_dir, "docs", "battle_header.md")
|
21 |
|
22 |
|
23 |
+
def remove_chat_tokens(text: str) -> str:
|
24 |
+
pattern = re.compile(r'</?(?:start_of_turn|end_of_turn)>')
|
25 |
+
return pattern.sub('', text).strip()
|
26 |
+
|
27 |
+
|
28 |
@spaces.GPU(duration=30)
|
29 |
def generate(chat_history: list,
|
30 |
model_id: str,
|
|
|
86 |
history.append({"role": "assistant", "content": ""})
|
87 |
conv_history = history[:-1]
|
88 |
for text in generate(conv_history, model_id):
|
89 |
+
cleaned_text = remove_chat_tokens(text)
|
90 |
+
history[-1]["content"] = cleaned_text
|
91 |
yield history, gr.update(interactive=True), gr.update(interactive=True)
|
92 |
|
93 |
|
|
|
96 |
history.append({"role": "assistant", "content": ""})
|
97 |
conv_history = history[:-1]
|
98 |
for text in generate(conv_history, model_id):
|
99 |
+
cleaned_text = remove_chat_tokens(text)
|
100 |
+
history[-1]["content"] = cleaned_text
|
101 |
yield history, gr.update(interactive=True), gr.update(interactive=True)
|
102 |
|
103 |
|
indiebot_arena/ui/playground.py
CHANGED
@@ -4,7 +4,7 @@ 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"
|
@@ -29,7 +29,8 @@ def bot1_response(history, model_id):
|
|
29 |
history.append({"role": "assistant", "content": ""})
|
30 |
conv_history = history[:-1]
|
31 |
for text in generate(conv_history, model_id):
|
32 |
-
|
|
|
33 |
yield history
|
34 |
|
35 |
|
|
|
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, remove_chat_tokens
|
8 |
from indiebot_arena.util.cache_manager import get_free_space_gb, clear_hf_cache
|
9 |
|
10 |
DESCRIPTION = "### 💬 Playground"
|
|
|
29 |
history.append({"role": "assistant", "content": ""})
|
30 |
conv_history = history[:-1]
|
31 |
for text in generate(conv_history, model_id):
|
32 |
+
cleaned_text = remove_chat_tokens(text)
|
33 |
+
history[-1]["content"] = cleaned_text
|
34 |
yield history
|
35 |
|
36 |
|