Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -6,15 +6,25 @@ import spaces
|
|
6 |
import transformers
|
7 |
from transformers import pipeline
|
8 |
|
9 |
-
#
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
# ์ต์ข
๋ต๋ณ์ ๊ฐ์งํ๊ธฐ ์ํ ๋ง์ปค
|
20 |
ANSWER_MARKER = "**๋ต๋ณ**"
|
@@ -74,6 +84,27 @@ def rebuild_messages(history: list):
|
|
74 |
return messages
|
75 |
|
76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
@spaces.GPU
|
78 |
def bot(
|
79 |
history: list,
|
@@ -83,6 +114,18 @@ def bot(
|
|
83 |
temperature: float,
|
84 |
):
|
85 |
"""๋ชจ๋ธ์ด ์ง๋ฌธ์ ๋ต๋ณํ๋๋ก ํ๊ธฐ"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
|
87 |
# ๋์ค์ ์ค๋ ๋์์ ํ ํฐ์ ์คํธ๋ฆผ์ผ๋ก ๊ฐ์ ธ์ค๊ธฐ ์ํจ
|
88 |
streamer = transformers.TextIteratorStreamer(
|
@@ -140,10 +183,16 @@ def bot(
|
|
140 |
yield history
|
141 |
|
142 |
|
143 |
-
with gr.Blocks(fill_height=True, title="
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
with gr.Row(scale=1):
|
145 |
with gr.Column(scale=5):
|
146 |
-
|
147 |
chatbot = gr.Chatbot(
|
148 |
scale=1,
|
149 |
type="messages",
|
@@ -156,7 +205,20 @@ with gr.Blocks(fill_height=True, title="๋ชจ๋ LLM ๋ชจ๋ธ์ ์ถ๋ก ๋ฅ๋ ฅ ๋ถ
|
|
156 |
placeholder="์ฌ๊ธฐ์ ์ง๋ฌธ์ ์
๋ ฅํ์ธ์.",
|
157 |
autofocus=True,
|
158 |
)
|
|
|
159 |
with gr.Column(scale=1):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
gr.Markdown("""## ๋งค๊ฐ๋ณ์ ์กฐ์ """)
|
161 |
num_tokens = gr.Slider(
|
162 |
50,
|
@@ -176,7 +238,18 @@ with gr.Blocks(fill_height=True, title="๋ชจ๋ LLM ๋ชจ๋ธ์ ์ถ๋ก ๋ฅ๋ ฅ ๋ถ
|
|
176 |
)
|
177 |
do_sample = gr.Checkbox(True, label="์ํ๋ง ์ฌ์ฉ")
|
178 |
temperature = gr.Slider(0.1, 1.0, 0.7, step=0.1, label="์จ๋")
|
179 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
180 |
|
181 |
# ์ฌ์ฉ์๊ฐ ๋ฉ์์ง๋ฅผ ์ ์ถํ๋ฉด ๋ด์ด ์๋ตํฉ๋๋ค
|
182 |
msg.submit(
|
|
|
6 |
import transformers
|
7 |
from transformers import pipeline
|
8 |
|
9 |
+
# ์ฌ์ฉ ๊ฐ๋ฅํ ๋ชจ๋ธ ๋ชฉ๋ก
|
10 |
+
available_models = {
|
11 |
+
"Qwen/Qwen2-1.5B-Instruct": "Qwen 2 (1.5B)",
|
12 |
+
"Qwen/Qwen2.5-72B-Instruct": "Qwen 2.5 (72B)",
|
13 |
+
"Hermes-3-Llama-3.1-8B": "Hermes 3 Llama 3.1 (8B)",
|
14 |
+
"Qwen/Qwen2.5-Coder-32B-Instruct": "Qwen 2.5 Coder (32B)",
|
15 |
+
"nvidia/Llama-3.1-Nemotron-70B-Instruct-HF": "Nvidia Nemotron (70B)",
|
16 |
+
"CohereForAI/c4ai-command-r-plus-08-2024": "Cohere Command R+ (08/2024)",
|
17 |
+
"mistralai/Mistral-Small-3.1-24B-Instruct-2503": "Mistral Small 3.1 (24B)",
|
18 |
+
"google/gemma-3-27b-it": "Google Gemma 3 (27B)",
|
19 |
+
"gemma-3-27b-it-abliterated": "Gemma 3 Abliterated (27B)",
|
20 |
+
"nvidia/Llama-3.1-Nemotron-Nano-8B-v1": "Nvidia Nemotron Nano (8B)",
|
21 |
+
"bartowski/mistralai_Mistral-Small-3.1-24B-Instruct-2503-GGUF": "Mistral Small GGUF (24B)",
|
22 |
+
"CohereForAI/c4ai-command-a-03-2025": "Cohere Command A (03/2025)",
|
23 |
+
"open-r1/OlympicCoder-32B": "Olympic Coder (32B)"
|
24 |
+
}
|
25 |
+
|
26 |
+
# ๋ชจ๋ธ๊ณผ ํ ํฌ๋์ด์ ๋ก๋ฉ์ ์ํ ์ ์ญ ๋ณ์
|
27 |
+
pipe = None
|
28 |
|
29 |
# ์ต์ข
๋ต๋ณ์ ๊ฐ์งํ๊ธฐ ์ํ ๋ง์ปค
|
30 |
ANSWER_MARKER = "**๋ต๋ณ**"
|
|
|
84 |
return messages
|
85 |
|
86 |
|
87 |
+
def load_model(model_names):
|
88 |
+
"""์ ํ๋ ๋ชจ๋ธ ์ด๋ฆ์ ๋ฐ๋ผ ๋ชจ๋ธ ๋ก๋"""
|
89 |
+
global pipe
|
90 |
+
|
91 |
+
# ๋ชจ๋ธ์ด ์ ํ๋์ง ์์์ ๊ฒฝ์ฐ ๊ธฐ๋ณธ๊ฐ ์ง์
|
92 |
+
if not model_names:
|
93 |
+
model_name = "Qwen/Qwen2-1.5B-Instruct"
|
94 |
+
else:
|
95 |
+
# ์ฒซ ๋ฒ์งธ ์ ํ๋ ๋ชจ๋ธ ์ฌ์ฉ (๋์ค์ ์ฌ๋ฌ ๋ชจ๋ธ ์์๋ธ๋ก ํ์ฅ ๊ฐ๋ฅ)
|
96 |
+
model_name = model_names[0]
|
97 |
+
|
98 |
+
pipe = pipeline(
|
99 |
+
"text-generation",
|
100 |
+
model=model_name,
|
101 |
+
device_map="auto",
|
102 |
+
torch_dtype="auto",
|
103 |
+
)
|
104 |
+
|
105 |
+
return f"๋ชจ๋ธ '{model_name}'์ด(๊ฐ) ๋ก๋๋์์ต๋๋ค."
|
106 |
+
|
107 |
+
|
108 |
@spaces.GPU
|
109 |
def bot(
|
110 |
history: list,
|
|
|
114 |
temperature: float,
|
115 |
):
|
116 |
"""๋ชจ๋ธ์ด ์ง๋ฌธ์ ๋ต๋ณํ๋๋ก ํ๊ธฐ"""
|
117 |
+
global pipe
|
118 |
+
|
119 |
+
# ๋ชจ๋ธ์ด ๋ก๋๋์ง ์์๋ค๋ฉด ์ค๋ฅ ๋ฉ์์ง ํ์
|
120 |
+
if pipe is None:
|
121 |
+
history.append(
|
122 |
+
gr.ChatMessage(
|
123 |
+
role="assistant",
|
124 |
+
content="๋ชจ๋ธ์ด ๋ก๋๋์ง ์์์ต๋๋ค. ํ๋ ์ด์์ ๋ชจ๋ธ์ ์ ํํด ์ฃผ์ธ์.",
|
125 |
+
)
|
126 |
+
)
|
127 |
+
yield history
|
128 |
+
return
|
129 |
|
130 |
# ๋์ค์ ์ค๋ ๋์์ ํ ํฐ์ ์คํธ๋ฆผ์ผ๋ก ๊ฐ์ ธ์ค๊ธฐ ์ํจ
|
131 |
streamer = transformers.TextIteratorStreamer(
|
|
|
183 |
yield history
|
184 |
|
185 |
|
186 |
+
with gr.Blocks(fill_height=True, title="ThinkFlow - Step-by-step Reasoning Service") as demo:
|
187 |
+
# ์๋จ์ ํ์ดํ๊ณผ ์ค๋ช
์ถ๊ฐ
|
188 |
+
gr.Markdown("""
|
189 |
+
# ThinkFlow
|
190 |
+
## A thought amplification service that implants step-by-step reasoning abilities into LLMs without model modification
|
191 |
+
""")
|
192 |
+
|
193 |
with gr.Row(scale=1):
|
194 |
with gr.Column(scale=5):
|
195 |
+
# ์ฑํ
์ธํฐํ์ด์ค
|
196 |
chatbot = gr.Chatbot(
|
197 |
scale=1,
|
198 |
type="messages",
|
|
|
205 |
placeholder="์ฌ๊ธฐ์ ์ง๋ฌธ์ ์
๋ ฅํ์ธ์.",
|
206 |
autofocus=True,
|
207 |
)
|
208 |
+
|
209 |
with gr.Column(scale=1):
|
210 |
+
# ๋ชจ๋ธ ์ ํ ์น์
์ถ๊ฐ
|
211 |
+
gr.Markdown("""## ๋ชจ๋ธ ์ ํ""")
|
212 |
+
model_selector = gr.CheckboxGroup(
|
213 |
+
choices=list(available_models.values()),
|
214 |
+
value=[available_models["Qwen/Qwen2-1.5B-Instruct"]], # ๊ธฐ๋ณธ๊ฐ
|
215 |
+
label="์ฌ์ฉํ LLM ๋ชจ๋ธ ์ ํ (๋ณต์ ์ ํ ๊ฐ๋ฅ)",
|
216 |
+
)
|
217 |
+
|
218 |
+
# ๋ชจ๋ธ ๋ก๋ ๋ฒํผ
|
219 |
+
load_model_btn = gr.Button("๋ชจ๋ธ ๋ก๋")
|
220 |
+
model_status = gr.Textbox(label="๋ชจ๋ธ ์ํ", interactive=False)
|
221 |
+
|
222 |
gr.Markdown("""## ๋งค๊ฐ๋ณ์ ์กฐ์ """)
|
223 |
num_tokens = gr.Slider(
|
224 |
50,
|
|
|
238 |
)
|
239 |
do_sample = gr.Checkbox(True, label="์ํ๋ง ์ฌ์ฉ")
|
240 |
temperature = gr.Slider(0.1, 1.0, 0.7, step=0.1, label="์จ๋")
|
241 |
+
|
242 |
+
# ์ ํ๋ ๋ชจ๋ธ ๋ก๋ ์ด๋ฒคํธ ์ฐ๊ฒฐ
|
243 |
+
def get_model_names(selected_models):
|
244 |
+
# ํ์ ์ด๋ฆ์์ ์๋ ๋ชจ๋ธ ์ด๋ฆ์ผ๋ก ๋ณํ
|
245 |
+
inverse_map = {v: k for k, v in available_models.items()}
|
246 |
+
return [inverse_map[model] for model in selected_models]
|
247 |
+
|
248 |
+
load_model_btn.click(
|
249 |
+
lambda selected: load_model(get_model_names(selected)),
|
250 |
+
inputs=[model_selector],
|
251 |
+
outputs=[model_status]
|
252 |
+
)
|
253 |
|
254 |
# ์ฌ์ฉ์๊ฐ ๋ฉ์์ง๋ฅผ ์ ์ถํ๋ฉด ๋ด์ด ์๋ตํฉ๋๋ค
|
255 |
msg.submit(
|