Spaces:
Running
on
T4
Running
on
T4
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,7 +12,7 @@ class VibeThinkerVLLM:
|
|
| 12 |
model=self.model_path,
|
| 13 |
dtype="bfloat16",
|
| 14 |
gpu_memory_utilization=0.9,
|
| 15 |
-
max_model_len=40960,
|
| 16 |
trust_remote_code=True
|
| 17 |
)
|
| 18 |
|
|
@@ -30,7 +30,7 @@ class VibeThinkerVLLM:
|
|
| 30 |
temperature=temperature,
|
| 31 |
max_tokens=max_tokens,
|
| 32 |
top_p=top_p,
|
| 33 |
-
top_k=-1,
|
| 34 |
)
|
| 35 |
|
| 36 |
print(f"Generating with vLLM (temp={temperature}, max_tokens={max_tokens})...")
|
|
@@ -43,66 +43,24 @@ class VibeThinkerVLLM:
|
|
| 43 |
|
| 44 |
def parse_model_output(text):
|
| 45 |
"""
|
| 46 |
-
Parse model output into structured components
|
| 47 |
-
- Thinking sections (within <think> tags)
|
| 48 |
-
- Regular text (chat messages)
|
| 49 |
-
- Code blocks (within ``` or <code> tags)
|
| 50 |
"""
|
| 51 |
-
|
| 52 |
sections = []
|
| 53 |
|
| 54 |
-
#
|
| 55 |
think_pattern = r'<think>(.*?)</think>'
|
| 56 |
code_pattern = r'```(\w+)?\n(.*?)```'
|
| 57 |
|
| 58 |
# Extract thinking sections
|
| 59 |
think_matches = list(re.finditer(think_pattern, text, re.DOTALL))
|
| 60 |
|
| 61 |
-
# Track positions
|
| 62 |
last_pos = 0
|
| 63 |
|
| 64 |
for match in think_matches:
|
| 65 |
-
#
|
| 66 |
before_text = text[last_pos:match.start()].strip()
|
| 67 |
if before_text:
|
| 68 |
-
|
| 69 |
-
code_blocks = list(re.finditer(code_pattern, before_text, re.DOTALL))
|
| 70 |
-
|
| 71 |
-
if code_blocks:
|
| 72 |
-
# Process text with code blocks
|
| 73 |
-
text_pos = 0
|
| 74 |
-
for code_match in code_blocks:
|
| 75 |
-
# Add text before code
|
| 76 |
-
pre_code_text = before_text[text_pos:code_match.start()].strip()
|
| 77 |
-
if pre_code_text:
|
| 78 |
-
sections.append({
|
| 79 |
-
'type': 'text',
|
| 80 |
-
'content': pre_code_text
|
| 81 |
-
})
|
| 82 |
-
|
| 83 |
-
# Add code block
|
| 84 |
-
language = code_match.group(1) or 'plaintext'
|
| 85 |
-
code_content = code_match.group(2).strip()
|
| 86 |
-
sections.append({
|
| 87 |
-
'type': 'code',
|
| 88 |
-
'language': language,
|
| 89 |
-
'content': code_content
|
| 90 |
-
})
|
| 91 |
-
|
| 92 |
-
text_pos = code_match.end()
|
| 93 |
-
|
| 94 |
-
# Add remaining text after last code block
|
| 95 |
-
remaining_text = before_text[text_pos:].strip()
|
| 96 |
-
if remaining_text:
|
| 97 |
-
sections.append({
|
| 98 |
-
'type': 'text',
|
| 99 |
-
'content': remaining_text
|
| 100 |
-
})
|
| 101 |
-
else:
|
| 102 |
-
sections.append({
|
| 103 |
-
'type': 'text',
|
| 104 |
-
'content': before_text
|
| 105 |
-
})
|
| 106 |
|
| 107 |
# Add thinking section
|
| 108 |
think_content = match.group(1).strip()
|
|
@@ -113,164 +71,68 @@ def parse_model_output(text):
|
|
| 113 |
|
| 114 |
last_pos = match.end()
|
| 115 |
|
| 116 |
-
#
|
| 117 |
remaining = text[last_pos:].strip()
|
| 118 |
if remaining:
|
| 119 |
-
|
| 120 |
-
code_blocks = list(re.finditer(code_pattern, remaining, re.DOTALL))
|
| 121 |
-
|
| 122 |
-
if code_blocks:
|
| 123 |
-
text_pos = 0
|
| 124 |
-
for code_match in code_blocks:
|
| 125 |
-
pre_code_text = remaining[text_pos:code_match.start()].strip()
|
| 126 |
-
if pre_code_text:
|
| 127 |
-
sections.append({
|
| 128 |
-
'type': 'text',
|
| 129 |
-
'content': pre_code_text
|
| 130 |
-
})
|
| 131 |
-
|
| 132 |
-
language = code_match.group(1) or 'plaintext'
|
| 133 |
-
code_content = code_match.group(2).strip()
|
| 134 |
-
sections.append({
|
| 135 |
-
'type': 'code',
|
| 136 |
-
'language': language,
|
| 137 |
-
'content': code_content
|
| 138 |
-
})
|
| 139 |
-
|
| 140 |
-
text_pos = code_match.end()
|
| 141 |
-
|
| 142 |
-
remaining_text = remaining[text_pos:].strip()
|
| 143 |
-
if remaining_text:
|
| 144 |
-
sections.append({
|
| 145 |
-
'type': 'text',
|
| 146 |
-
'content': remaining_text
|
| 147 |
-
})
|
| 148 |
-
else:
|
| 149 |
-
sections.append({
|
| 150 |
-
'type': 'text',
|
| 151 |
-
'content': remaining
|
| 152 |
-
})
|
| 153 |
|
| 154 |
return sections
|
| 155 |
|
| 156 |
|
| 157 |
-
def
|
| 158 |
-
"""
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
- Clean text rendering
|
| 163 |
-
"""
|
| 164 |
|
| 165 |
-
|
|
|
|
| 166 |
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
{section['content']}
|
| 177 |
-
</div>
|
| 178 |
-
</details>
|
| 179 |
-
""")
|
| 180 |
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
<div style="position: relative; padding: 0;">
|
| 190 |
-
<div style="position: absolute; top: 10px; right: 10px; z-index: 10;">
|
| 191 |
-
<button onclick="copyCode('{code_id}')" style="padding: 6px 12px; margin-right: 5px; background-color: #3498db; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 12px;">
|
| 192 |
-
π Copy
|
| 193 |
-
</button>
|
| 194 |
-
<button onclick="downloadCode('{code_id}', '{section['language']}')" style="padding: 6px 12px; background-color: #27ae60; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 12px;">
|
| 195 |
-
β¬οΈ Download
|
| 196 |
-
</button>
|
| 197 |
-
</div>
|
| 198 |
-
<pre id="{code_id}" style="margin: 0; padding: 40px 15px 15px 15px; background-color: #f8f9fa; border-top: 1px solid #3498db; overflow-x: auto; font-family: 'Courier New', monospace; font-size: 13px; line-height: 1.5;"><code class="language-{section['language']}">{section['content']}</code></pre>
|
| 199 |
-
</div>
|
| 200 |
-
</details>
|
| 201 |
-
""")
|
| 202 |
|
| 203 |
-
|
| 204 |
-
# Regular text output
|
| 205 |
-
html_parts.append(f"""
|
| 206 |
-
<div class="text-section" style="margin: 15px 0; padding: 15px; border: 1px solid #bdc3c7; border-radius: 8px; background-color: #ffffff; white-space: pre-wrap; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; font-size: 14px; line-height: 1.8; color: #2c3e50;">
|
| 207 |
-
{section['content']}
|
| 208 |
-
</div>
|
| 209 |
-
""")
|
| 210 |
-
|
| 211 |
-
# Add JavaScript for copy and download functionality
|
| 212 |
-
js_code = """
|
| 213 |
-
<script>
|
| 214 |
-
function copyCode(elementId) {
|
| 215 |
-
const codeElement = document.getElementById(elementId);
|
| 216 |
-
const code = codeElement.textContent;
|
| 217 |
-
navigator.clipboard.writeText(code).then(() => {
|
| 218 |
-
alert('Code copied to clipboard!');
|
| 219 |
-
}).catch(err => {
|
| 220 |
-
console.error('Failed to copy:', err);
|
| 221 |
-
});
|
| 222 |
-
}
|
| 223 |
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
'javascript': 'js',
|
| 232 |
-
'typescript': 'ts',
|
| 233 |
-
'html': 'html',
|
| 234 |
-
'css': 'css',
|
| 235 |
-
'java': 'java',
|
| 236 |
-
'cpp': 'cpp',
|
| 237 |
-
'c': 'c',
|
| 238 |
-
'ruby': 'rb',
|
| 239 |
-
'go': 'go',
|
| 240 |
-
'rust': 'rs',
|
| 241 |
-
'swift': 'swift',
|
| 242 |
-
'kotlin': 'kt',
|
| 243 |
-
'plaintext': 'txt'
|
| 244 |
-
};
|
| 245 |
-
|
| 246 |
-
const ext = extensions[language.toLowerCase()] || 'txt';
|
| 247 |
-
const filename = `code_snippet.${ext}`;
|
| 248 |
-
|
| 249 |
-
// Create blob and download
|
| 250 |
-
const blob = new Blob([code], { type: 'text/plain' });
|
| 251 |
-
const url = window.URL.createObjectURL(blob);
|
| 252 |
-
const a = document.createElement('a');
|
| 253 |
-
a.href = url;
|
| 254 |
-
a.download = filename;
|
| 255 |
-
document.body.appendChild(a);
|
| 256 |
-
a.click();
|
| 257 |
-
document.body.removeChild(a);
|
| 258 |
-
window.URL.revokeObjectURL(url);
|
| 259 |
-
}
|
| 260 |
-
</script>
|
| 261 |
-
"""
|
| 262 |
|
| 263 |
-
return
|
| 264 |
|
| 265 |
|
| 266 |
# Initialize model
|
| 267 |
print("Initializing VibeThinker-1.5B with vLLM...")
|
| 268 |
model = VibeThinkerVLLM()
|
| 269 |
|
| 270 |
-
|
| 271 |
def generate_response(prompt, temperature, max_tokens, top_p):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
if not prompt.strip():
|
| 273 |
-
|
|
|
|
| 274 |
|
| 275 |
try:
|
| 276 |
# Generate raw response
|
|
@@ -281,64 +143,102 @@ def generate_response(prompt, temperature, max_tokens, top_p):
|
|
| 281 |
top_p=top_p
|
| 282 |
)
|
| 283 |
|
| 284 |
-
# Parse
|
| 285 |
sections = parse_model_output(raw_response)
|
| 286 |
-
formatted_html = format_output_for_display(sections)
|
| 287 |
|
| 288 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 289 |
|
| 290 |
except Exception as e:
|
| 291 |
-
|
| 292 |
|
| 293 |
|
| 294 |
-
# Custom
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 299 |
|
| 300 |
-
.code-section summary:hover {
|
| 301 |
-
background-color: #d6eaf8;
|
| 302 |
-
}
|
| 303 |
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
}
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 321 |
gr.Markdown("""
|
| 322 |
# π§ VibeThinker-1.5B: Advanced Reasoning Interface
|
| 323 |
|
| 324 |
-
|
| 325 |
|
| 326 |
-
|
| 327 |
-
- π€ **Collapsible Thinking Sections
|
| 328 |
-
- π» **
|
| 329 |
-
- π **Clean
|
| 330 |
|
| 331 |
-
**Best for
|
| 332 |
|
| 333 |
-
[GitHub](https://github.com/WeiboAI/VibeThinker) | [
|
| 334 |
""")
|
| 335 |
|
| 336 |
with gr.Row():
|
| 337 |
with gr.Column(scale=1):
|
| 338 |
prompt_input = gr.Textbox(
|
| 339 |
-
label="Your Question",
|
| 340 |
-
placeholder="Ask a math problem or coding challenge (
|
| 341 |
-
lines=6
|
|
|
|
| 342 |
)
|
| 343 |
|
| 344 |
with gr.Accordion("βοΈ Advanced Settings", open=False):
|
|
@@ -347,7 +247,8 @@ with gr.Blocks(title="VibeThinker-1.5B Advanced", css=custom_css) as demo:
|
|
| 347 |
maximum=1.5,
|
| 348 |
value=0.6,
|
| 349 |
step=0.1,
|
| 350 |
-
label="Temperature
|
|
|
|
| 351 |
)
|
| 352 |
|
| 353 |
max_tokens_slider = gr.Slider(
|
|
@@ -355,7 +256,8 @@ with gr.Blocks(title="VibeThinker-1.5B Advanced", css=custom_css) as demo:
|
|
| 355 |
maximum=40960,
|
| 356 |
value=8192,
|
| 357 |
step=512,
|
| 358 |
-
label="Max Tokens"
|
|
|
|
| 359 |
)
|
| 360 |
|
| 361 |
top_p_slider = gr.Slider(
|
|
@@ -363,58 +265,89 @@ with gr.Blocks(title="VibeThinker-1.5B Advanced", css=custom_css) as demo:
|
|
| 363 |
maximum=1.0,
|
| 364 |
value=0.95,
|
| 365 |
step=0.05,
|
| 366 |
-
label="Top P"
|
|
|
|
| 367 |
)
|
| 368 |
|
| 369 |
-
|
| 370 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 371 |
|
| 372 |
with gr.Column(scale=1):
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 377 |
|
| 378 |
-
# Example
|
| 379 |
gr.Examples(
|
| 380 |
examples=[
|
| 381 |
-
["Make me a single page
|
| 382 |
-
["Solve
|
| 383 |
-
["Write
|
| 384 |
-
["Prove that
|
| 385 |
],
|
| 386 |
inputs=[prompt_input, temperature_slider, max_tokens_slider, top_p_slider],
|
| 387 |
-
label="π Example Problems"
|
|
|
|
| 388 |
)
|
| 389 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 390 |
# Event handlers
|
|
|
|
|
|
|
|
|
|
| 391 |
submit_btn.click(
|
| 392 |
fn=generate_response,
|
| 393 |
inputs=[prompt_input, temperature_slider, max_tokens_slider, top_p_slider],
|
| 394 |
-
outputs=
|
|
|
|
| 395 |
)
|
| 396 |
|
| 397 |
clear_btn.click(
|
| 398 |
-
fn=
|
| 399 |
inputs=[],
|
| 400 |
-
outputs=[prompt_input,
|
| 401 |
)
|
| 402 |
-
|
| 403 |
-
gr.Markdown("""
|
| 404 |
-
---
|
| 405 |
-
### π Performance Comparison:
|
| 406 |
-
|
| 407 |
-
| Metric | VibeThinker-1.5B | DeepSeek R1 (671B) | Size Ratio |
|
| 408 |
-
|--------|------------------|---------------------|------------|
|
| 409 |
-
| AIME24 | **80.3** | 79.8 | **400Γ smaller** |
|
| 410 |
-
| AIME25 | **74.4** | 70.0 | **400Γ smaller** |
|
| 411 |
-
| HMMT25 | **50.4** | 41.7 | **400Γ smaller** |
|
| 412 |
-
| Training Cost | **$7,800** | $294,000+ | **40Γ cheaper** |
|
| 413 |
-
|
| 414 |
-
π **Powered by vLLM** for ultra-fast inference on T4 GPUs
|
| 415 |
-
""")
|
| 416 |
|
| 417 |
-
|
|
|
|
| 418 |
if __name__ == "__main__":
|
| 419 |
-
demo.queue(
|
| 420 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
model=self.model_path,
|
| 13 |
dtype="bfloat16",
|
| 14 |
gpu_memory_utilization=0.9,
|
| 15 |
+
max_model_len=40960,
|
| 16 |
trust_remote_code=True
|
| 17 |
)
|
| 18 |
|
|
|
|
| 30 |
temperature=temperature,
|
| 31 |
max_tokens=max_tokens,
|
| 32 |
top_p=top_p,
|
| 33 |
+
top_k=-1,
|
| 34 |
)
|
| 35 |
|
| 36 |
print(f"Generating with vLLM (temp={temperature}, max_tokens={max_tokens})...")
|
|
|
|
| 43 |
|
| 44 |
def parse_model_output(text):
|
| 45 |
"""
|
| 46 |
+
Parse model output into structured components using Gradio 5 native components
|
|
|
|
|
|
|
|
|
|
| 47 |
"""
|
|
|
|
| 48 |
sections = []
|
| 49 |
|
| 50 |
+
# Patterns
|
| 51 |
think_pattern = r'<think>(.*?)</think>'
|
| 52 |
code_pattern = r'```(\w+)?\n(.*?)```'
|
| 53 |
|
| 54 |
# Extract thinking sections
|
| 55 |
think_matches = list(re.finditer(think_pattern, text, re.DOTALL))
|
| 56 |
|
|
|
|
| 57 |
last_pos = 0
|
| 58 |
|
| 59 |
for match in think_matches:
|
| 60 |
+
# Process text before thinking section
|
| 61 |
before_text = text[last_pos:match.start()].strip()
|
| 62 |
if before_text:
|
| 63 |
+
sections.extend(parse_text_with_code(before_text))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
# Add thinking section
|
| 66 |
think_content = match.group(1).strip()
|
|
|
|
| 71 |
|
| 72 |
last_pos = match.end()
|
| 73 |
|
| 74 |
+
# Process remaining text
|
| 75 |
remaining = text[last_pos:].strip()
|
| 76 |
if remaining:
|
| 77 |
+
sections.extend(parse_text_with_code(remaining))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
return sections
|
| 80 |
|
| 81 |
|
| 82 |
+
def parse_text_with_code(text):
|
| 83 |
+
"""Helper function to parse text containing code blocks"""
|
| 84 |
+
sections = []
|
| 85 |
+
code_pattern = r'```(\w+)?\n(.*?)```'
|
| 86 |
+
code_blocks = list(re.finditer(code_pattern, text, re.DOTALL))
|
|
|
|
|
|
|
| 87 |
|
| 88 |
+
if not code_blocks:
|
| 89 |
+
return [{'type': 'text', 'content': text}]
|
| 90 |
|
| 91 |
+
text_pos = 0
|
| 92 |
+
for code_match in code_blocks:
|
| 93 |
+
# Add text before code
|
| 94 |
+
pre_code_text = text[text_pos:code_match.start()].strip()
|
| 95 |
+
if pre_code_text:
|
| 96 |
+
sections.append({
|
| 97 |
+
'type': 'text',
|
| 98 |
+
'content': pre_code_text
|
| 99 |
+
})
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
+
# Add code block
|
| 102 |
+
language = code_match.group(1) or 'python'
|
| 103 |
+
code_content = code_match.group(2).strip()
|
| 104 |
+
sections.append({
|
| 105 |
+
'type': 'code',
|
| 106 |
+
'language': language,
|
| 107 |
+
'content': code_content
|
| 108 |
+
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
+
text_pos = code_match.end()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
+
# Add remaining text
|
| 113 |
+
remaining_text = text[text_pos:].strip()
|
| 114 |
+
if remaining_text:
|
| 115 |
+
sections.append({
|
| 116 |
+
'type': 'text',
|
| 117 |
+
'content': remaining_text
|
| 118 |
+
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
+
return sections
|
| 121 |
|
| 122 |
|
| 123 |
# Initialize model
|
| 124 |
print("Initializing VibeThinker-1.5B with vLLM...")
|
| 125 |
model = VibeThinkerVLLM()
|
| 126 |
|
| 127 |
+
|
| 128 |
def generate_response(prompt, temperature, max_tokens, top_p):
|
| 129 |
+
"""
|
| 130 |
+
Generate and parse response using Gradio 5 native components
|
| 131 |
+
Returns a list of components to render
|
| 132 |
+
"""
|
| 133 |
if not prompt.strip():
|
| 134 |
+
yield [gr.Markdown("β οΈ Please enter a question.")]
|
| 135 |
+
return
|
| 136 |
|
| 137 |
try:
|
| 138 |
# Generate raw response
|
|
|
|
| 143 |
top_p=top_p
|
| 144 |
)
|
| 145 |
|
| 146 |
+
# Parse the response
|
| 147 |
sections = parse_model_output(raw_response)
|
|
|
|
| 148 |
|
| 149 |
+
# Build component list for Gradio 5
|
| 150 |
+
components = []
|
| 151 |
+
|
| 152 |
+
for i, section in enumerate(sections):
|
| 153 |
+
if section['type'] == 'thinking':
|
| 154 |
+
# Use Accordion for collapsible thinking
|
| 155 |
+
with gr.Accordion("π€ Thinking Process", open=False):
|
| 156 |
+
components.append(gr.Textbox(
|
| 157 |
+
value=section['content'],
|
| 158 |
+
lines=20,
|
| 159 |
+
max_lines=50,
|
| 160 |
+
show_label=False,
|
| 161 |
+
container=False,
|
| 162 |
+
interactive=False
|
| 163 |
+
))
|
| 164 |
+
|
| 165 |
+
elif section['type'] == 'code':
|
| 166 |
+
# Use native Code component in Gradio 5
|
| 167 |
+
with gr.Accordion(f"π» Code ({section['language']})", open=True):
|
| 168 |
+
components.append(gr.Code(
|
| 169 |
+
value=section['content'],
|
| 170 |
+
language=section['language'],
|
| 171 |
+
lines=20,
|
| 172 |
+
show_label=False,
|
| 173 |
+
interactive=False
|
| 174 |
+
))
|
| 175 |
+
|
| 176 |
+
else: # text
|
| 177 |
+
components.append(gr.Markdown(section['content']))
|
| 178 |
+
|
| 179 |
+
yield components
|
| 180 |
|
| 181 |
except Exception as e:
|
| 182 |
+
yield [gr.Markdown(f"β **Error:** {str(e)}")]
|
| 183 |
|
| 184 |
|
| 185 |
+
# Custom theme for Gradio 5
|
| 186 |
+
theme = gr.themes.Soft(
|
| 187 |
+
primary_hue="blue",
|
| 188 |
+
secondary_hue="purple",
|
| 189 |
+
neutral_hue="slate",
|
| 190 |
+
font=[gr.themes.GoogleFont("Inter"), "system-ui", "sans-serif"],
|
| 191 |
+
).set(
|
| 192 |
+
button_primary_background_fill="*primary_600",
|
| 193 |
+
button_primary_background_fill_hover="*primary_700",
|
| 194 |
+
block_label_text_weight="600",
|
| 195 |
+
block_title_text_weight="700",
|
| 196 |
+
)
|
| 197 |
|
|
|
|
|
|
|
|
|
|
| 198 |
|
| 199 |
+
# Gradio 5 UI with modern components
|
| 200 |
+
with gr.Blocks(
|
| 201 |
+
title="VibeThinker-1.5B Advanced",
|
| 202 |
+
theme=theme,
|
| 203 |
+
fill_height=False,
|
| 204 |
+
css="""
|
| 205 |
+
.thinking-box {
|
| 206 |
+
background-color: #fff9e6;
|
| 207 |
+
border: 2px solid #f39c12;
|
| 208 |
+
border-radius: 8px;
|
| 209 |
+
padding: 15px;
|
| 210 |
+
font-family: 'Courier New', monospace;
|
| 211 |
+
}
|
| 212 |
+
.code-box {
|
| 213 |
+
background-color: #e8f4fd;
|
| 214 |
+
border: 2px solid #3498db;
|
| 215 |
+
border-radius: 8px;
|
| 216 |
+
}
|
| 217 |
+
""",
|
| 218 |
+
) as demo:
|
| 219 |
+
|
| 220 |
gr.Markdown("""
|
| 221 |
# π§ VibeThinker-1.5B: Advanced Reasoning Interface
|
| 222 |
|
| 223 |
+
**β‘ Powered by vLLM** for 10-20x faster inference on GPU!
|
| 224 |
|
| 225 |
+
### β¨ Features:
|
| 226 |
+
- π€ **Collapsible Thinking Sections** - Explore the model's reasoning process
|
| 227 |
+
- π» **Syntax-Highlighted Code** - Native code display with copy functionality
|
| 228 |
+
- π **Clean Markdown Output** - Beautiful formatting for text responses
|
| 229 |
|
| 230 |
+
**Best for:** Competitive math problems and algorithm coding challenges
|
| 231 |
|
| 232 |
+
[GitHub](https://github.com/WeiboAI/VibeThinker) | [Model](https://huggingface.co/WeiboAI/VibeThinker-1.5B) | [Paper](https://huggingface.co/papers/2511.06221)
|
| 233 |
""")
|
| 234 |
|
| 235 |
with gr.Row():
|
| 236 |
with gr.Column(scale=1):
|
| 237 |
prompt_input = gr.Textbox(
|
| 238 |
+
label="π¬ Your Question",
|
| 239 |
+
placeholder="Ask a math problem or coding challenge (English works best)...",
|
| 240 |
+
lines=6,
|
| 241 |
+
max_lines=15
|
| 242 |
)
|
| 243 |
|
| 244 |
with gr.Accordion("βοΈ Advanced Settings", open=False):
|
|
|
|
| 247 |
maximum=1.5,
|
| 248 |
value=0.6,
|
| 249 |
step=0.1,
|
| 250 |
+
label="π‘οΈ Temperature",
|
| 251 |
+
info="0.6 or 1.0 recommended"
|
| 252 |
)
|
| 253 |
|
| 254 |
max_tokens_slider = gr.Slider(
|
|
|
|
| 256 |
maximum=40960,
|
| 257 |
value=8192,
|
| 258 |
step=512,
|
| 259 |
+
label="π Max Tokens",
|
| 260 |
+
info="Model supports up to 40,960 tokens"
|
| 261 |
)
|
| 262 |
|
| 263 |
top_p_slider = gr.Slider(
|
|
|
|
| 265 |
maximum=1.0,
|
| 266 |
value=0.95,
|
| 267 |
step=0.05,
|
| 268 |
+
label="π― Top P",
|
| 269 |
+
info="Nucleus sampling parameter"
|
| 270 |
)
|
| 271 |
|
| 272 |
+
with gr.Row():
|
| 273 |
+
submit_btn = gr.Button(
|
| 274 |
+
"π Generate Solution",
|
| 275 |
+
variant="primary",
|
| 276 |
+
scale=2
|
| 277 |
+
)
|
| 278 |
+
clear_btn = gr.Button(
|
| 279 |
+
"ποΈ Clear",
|
| 280 |
+
variant="secondary",
|
| 281 |
+
scale=1
|
| 282 |
+
)
|
| 283 |
|
| 284 |
with gr.Column(scale=1):
|
| 285 |
+
# Output column using render for dynamic components
|
| 286 |
+
output_column = gr.Column()
|
| 287 |
+
|
| 288 |
+
with output_column:
|
| 289 |
+
initial_state = gr.Markdown(
|
| 290 |
+
"""
|
| 291 |
+
<div style='text-align: center; padding: 60px; color: #7f8c8d;'>
|
| 292 |
+
<h3>π Ready to solve problems!</h3>
|
| 293 |
+
<p>Enter your question and click Generate Solution</p>
|
| 294 |
+
</div>
|
| 295 |
+
"""
|
| 296 |
+
)
|
| 297 |
|
| 298 |
+
# Example problems
|
| 299 |
gr.Examples(
|
| 300 |
examples=[
|
| 301 |
+
["Make me a single page HTML application that takes a color and outputs a color theme", 0.6, 16384, 0.95],
|
| 302 |
+
["Solve: Find the number of positive integers n β€ 1000 such that n^2 + n + 41 is prime.", 0.6, 12288, 0.95],
|
| 303 |
+
["Write an efficient Python implementation of the Sieve of Eratosthenes algorithm.", 0.6, 8192, 0.95],
|
| 304 |
+
["Prove using mathematical induction that 1 + 2 + 3 + ... + n = n(n+1)/2", 0.6, 8192, 0.95],
|
| 305 |
],
|
| 306 |
inputs=[prompt_input, temperature_slider, max_tokens_slider, top_p_slider],
|
| 307 |
+
label="π Example Problems",
|
| 308 |
+
examples_per_page=4
|
| 309 |
)
|
| 310 |
|
| 311 |
+
gr.Markdown("""
|
| 312 |
+
---
|
| 313 |
+
### π Performance Highlights:
|
| 314 |
+
|
| 315 |
+
| Benchmark | VibeThinker-1.5B | DeepSeek R1 (671B) | Advantage |
|
| 316 |
+
|-----------|------------------|---------------------|-----------|
|
| 317 |
+
| **AIME24** | **80.3** β¨ | 79.8 | 400Γ smaller! |
|
| 318 |
+
| **AIME25** | **74.4** β¨ | 70.0 | 400Γ smaller! |
|
| 319 |
+
| **HMMT25** | **50.4** β¨ | 41.7 | 400Γ smaller! |
|
| 320 |
+
| **Training Cost** | **$7,800** | $294,000+ | 40Γ cheaper! |
|
| 321 |
+
|
| 322 |
+
π‘ **Powered by Spectrum-to-Signal Principle (SSP)** training framework
|
| 323 |
+
""")
|
| 324 |
+
|
| 325 |
# Event handlers
|
| 326 |
+
def clear_interface():
|
| 327 |
+
return "", None
|
| 328 |
+
|
| 329 |
submit_btn.click(
|
| 330 |
fn=generate_response,
|
| 331 |
inputs=[prompt_input, temperature_slider, max_tokens_slider, top_p_slider],
|
| 332 |
+
outputs=[output_column],
|
| 333 |
+
show_progress="full"
|
| 334 |
)
|
| 335 |
|
| 336 |
clear_btn.click(
|
| 337 |
+
fn=clear_interface,
|
| 338 |
inputs=[],
|
| 339 |
+
outputs=[prompt_input, output_column]
|
| 340 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 341 |
|
| 342 |
+
|
| 343 |
+
# Launch with Gradio 5 optimizations
|
| 344 |
if __name__ == "__main__":
|
| 345 |
+
demo.queue(
|
| 346 |
+
max_size=20,
|
| 347 |
+
default_concurrency_limit=10
|
| 348 |
+
)
|
| 349 |
+
demo.launch(
|
| 350 |
+
ssr_mode=True, # Enable server-side rendering for faster loads
|
| 351 |
+
show_api=True,
|
| 352 |
+
show_error=True,
|
| 353 |
+
)
|