Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -134,6 +134,19 @@ def extract_think(text):
|
|
134 |
text = re.sub(r"<.*?>", "", text.split("<CONCLUSION>")[0]) # Loại bỏ tất cả các tag <...>
|
135 |
conclusion_part = extract_conclusion(text)
|
136 |
return text.replace(conclusion_part, "").strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
|
138 |
model = AutoModel.from_pretrained(
|
139 |
"5CD-AI/Vintern-3B-R-beta",
|
@@ -142,6 +155,7 @@ model = AutoModel.from_pretrained(
|
|
142 |
trust_remote_code=True,
|
143 |
use_flash_attn=True,
|
144 |
).eval().cuda()
|
|
|
145 |
tokenizer = AutoTokenizer.from_pretrained("5CD-AI/Vintern-3B-R-beta", trust_remote_code=True, use_fast=False)
|
146 |
|
147 |
global_think_mode =False
|
@@ -236,7 +250,7 @@ We currently only support one image at the start of the context! Please start a
|
|
236 |
yield generated_text_without_prompt
|
237 |
else:
|
238 |
####################################################### thinking #######################################################
|
239 |
-
generation_config = dict(max_new_tokens= 2000, do_sample=False, num_beams =
|
240 |
|
241 |
if len(history) == 0:
|
242 |
if pixel_values is not None:
|
@@ -263,9 +277,11 @@ We currently only support one image at the start of the context! Please start a
|
|
263 |
response, conv_history = model.chat(tokenizer, pixel_values, question, generation_config, history=conv_history, return_history=True)
|
264 |
|
265 |
print(f'User: {question}\nAssistant: {response}')
|
266 |
-
think_part = extract_think(response)
|
267 |
conclusion_part = extract_conclusion(response)
|
268 |
-
|
|
|
|
|
269 |
buffer = ""
|
270 |
thinking = think_part
|
271 |
|
@@ -276,7 +292,7 @@ We currently only support one image at the start of the context! Please start a
|
|
276 |
for char in thinking:
|
277 |
temp_text += char
|
278 |
yield accumulated_text + temp_text + "\n</code></pre>\n"
|
279 |
-
time.sleep(0.
|
280 |
|
281 |
accumulated_text += temp_text + "\n</code></pre>\n"
|
282 |
|
|
|
134 |
text = re.sub(r"<.*?>", "", text.split("<CONCLUSION>")[0]) # Loại bỏ tất cả các tag <...>
|
135 |
conclusion_part = extract_conclusion(text)
|
136 |
return text.replace(conclusion_part, "").strip()
|
137 |
+
|
138 |
+
def wrap_text(text, max_words=20):
|
139 |
+
lines = text.split('\n') # Cắt theo dòng trước
|
140 |
+
wrapped_lines = []
|
141 |
+
|
142 |
+
for line in lines:
|
143 |
+
words = line.split()
|
144 |
+
if len(words) > max_words:
|
145 |
+
wrapped_lines.extend([' '.join(words[i:i+max_words]) for i in range(0, len(words), max_words)])
|
146 |
+
else:
|
147 |
+
wrapped_lines.append(line)
|
148 |
+
|
149 |
+
return '\n'.join(wrapped_lines)
|
150 |
|
151 |
model = AutoModel.from_pretrained(
|
152 |
"5CD-AI/Vintern-3B-R-beta",
|
|
|
155 |
trust_remote_code=True,
|
156 |
use_flash_attn=True,
|
157 |
).eval().cuda()
|
158 |
+
|
159 |
tokenizer = AutoTokenizer.from_pretrained("5CD-AI/Vintern-3B-R-beta", trust_remote_code=True, use_fast=False)
|
160 |
|
161 |
global_think_mode =False
|
|
|
250 |
yield generated_text_without_prompt
|
251 |
else:
|
252 |
####################################################### thinking #######################################################
|
253 |
+
generation_config = dict(max_new_tokens= 2000, do_sample=False, num_beams = 2, repetition_penalty=2.0)
|
254 |
|
255 |
if len(history) == 0:
|
256 |
if pixel_values is not None:
|
|
|
277 |
response, conv_history = model.chat(tokenizer, pixel_values, question, generation_config, history=conv_history, return_history=True)
|
278 |
|
279 |
print(f'User: {question}\nAssistant: {response}')
|
280 |
+
think_part = wrap_text(extract_think(response))
|
281 |
conclusion_part = extract_conclusion(response)
|
282 |
+
if conclusion_part == "":
|
283 |
+
conclusion_part = think_part
|
284 |
+
|
285 |
buffer = ""
|
286 |
thinking = think_part
|
287 |
|
|
|
292 |
for char in thinking:
|
293 |
temp_text += char
|
294 |
yield accumulated_text + temp_text + "\n</code></pre>\n"
|
295 |
+
time.sleep(0.002)
|
296 |
|
297 |
accumulated_text += temp_text + "\n</code></pre>\n"
|
298 |
|