Benedikt Droste Claude Opus 4.5 commited on
Commit ·
c29cf49
1
Parent(s): b7a2bef
Consolidate to single tokenizer and fix CSS corner clipping
Browse files- Removed dual tokenizer setup (MistralTokenizer + AutoTokenizer)
- Now using single AutoTokenizer with tokenizer_type="mistral"
- Use apply_chat_template() instead of encode_chat_completion()
- Added overflow:visible CSS to prevent rounded corner clipping
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
app.py
CHANGED
|
@@ -17,8 +17,6 @@ import spacy
|
|
| 17 |
import spacy.cli
|
| 18 |
import torch
|
| 19 |
from mistralai import Mistral
|
| 20 |
-
from mistral_common.protocol.instruct.request import ChatCompletionRequest
|
| 21 |
-
from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
|
| 22 |
from transformers import AutoTokenizer, Mistral3ForConditionalGeneration, TextIteratorStreamer
|
| 23 |
|
| 24 |
|
|
@@ -27,7 +25,6 @@ from transformers import AutoTokenizer, Mistral3ForConditionalGeneration, TextIt
|
|
| 27 |
# ============================================================================
|
| 28 |
|
| 29 |
MODEL_ID = "ellamind/sui-1-24b"
|
| 30 |
-
HF_TOKENIZER_ID = "mistralai/Mistral-Small-3.1-24B-Instruct-2503"
|
| 31 |
|
| 32 |
LANGUAGES = {
|
| 33 |
"English": "en",
|
|
@@ -57,24 +54,31 @@ def download_spacy_models():
|
|
| 57 |
|
| 58 |
|
| 59 |
def load_model():
|
| 60 |
-
"""Load the sui-1-24b model and
|
| 61 |
print(f"Loading model: {MODEL_ID}")
|
| 62 |
-
|
| 63 |
-
tokenizer = MistralTokenizer.from_hf_hub(MODEL_ID)
|
| 64 |
model = Mistral3ForConditionalGeneration.from_pretrained(
|
| 65 |
MODEL_ID,
|
| 66 |
dtype=torch.bfloat16,
|
| 67 |
device_map="auto",
|
| 68 |
)
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
print("Model loaded successfully")
|
| 72 |
-
return model, tokenizer
|
| 73 |
|
| 74 |
|
| 75 |
# Initialize on startup
|
| 76 |
download_spacy_models()
|
| 77 |
-
model, tokenizer
|
| 78 |
nlp_cache: dict[str, spacy.Language] = {}
|
| 79 |
|
| 80 |
|
|
@@ -319,20 +323,23 @@ def generate_summary(
|
|
| 319 |
"""Generate summary with streaming output."""
|
| 320 |
tagged_text, tag_to_sentence, tag_to_pos = tag_sentences(text, lang_code)
|
| 321 |
num_sentences = len(tag_to_sentence)
|
| 322 |
-
|
| 323 |
prompt = build_prompt(tagged_text, words, language_name, custom_instruction)
|
| 324 |
messages = [{"role": "user", "content": prompt}]
|
| 325 |
-
|
| 326 |
-
|
|
|
|
|
|
|
|
|
|
| 327 |
|
| 328 |
-
streamer = TextIteratorStreamer(
|
| 329 |
|
| 330 |
gen_kwargs = {
|
| 331 |
"input_ids": inputs,
|
| 332 |
"streamer": streamer,
|
| 333 |
"max_new_tokens": 4096,
|
| 334 |
"do_sample": False,
|
| 335 |
-
"pad_token_id":
|
| 336 |
}
|
| 337 |
|
| 338 |
thread = Thread(target=model.generate, kwargs=gen_kwargs)
|
|
@@ -455,6 +462,15 @@ CSS = """
|
|
| 455 |
max-width: 1200px !important;
|
| 456 |
margin: 0 auto !important;
|
| 457 |
padding: 1.5rem 2rem !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 458 |
}
|
| 459 |
|
| 460 |
/* Header styling */
|
|
@@ -487,6 +503,7 @@ CSS = """
|
|
| 487 |
border-radius: 0.75rem !important;
|
| 488 |
border: 1px solid #e2e8f0 !important;
|
| 489 |
padding: 1rem !important;
|
|
|
|
| 490 |
}
|
| 491 |
|
| 492 |
.output-panel {
|
|
@@ -495,6 +512,7 @@ CSS = """
|
|
| 495 |
border: 1px solid #e2e8f0 !important;
|
| 496 |
padding: 1rem !important;
|
| 497 |
min-height: 300px;
|
|
|
|
| 498 |
}
|
| 499 |
|
| 500 |
/* Section headers - simpler, not uppercase */
|
|
|
|
| 17 |
import spacy.cli
|
| 18 |
import torch
|
| 19 |
from mistralai import Mistral
|
|
|
|
|
|
|
| 20 |
from transformers import AutoTokenizer, Mistral3ForConditionalGeneration, TextIteratorStreamer
|
| 21 |
|
| 22 |
|
|
|
|
| 25 |
# ============================================================================
|
| 26 |
|
| 27 |
MODEL_ID = "ellamind/sui-1-24b"
|
|
|
|
| 28 |
|
| 29 |
LANGUAGES = {
|
| 30 |
"English": "en",
|
|
|
|
| 54 |
|
| 55 |
|
| 56 |
def load_model():
|
| 57 |
+
"""Load the sui-1-24b model and tokenizer."""
|
| 58 |
print(f"Loading model: {MODEL_ID}")
|
| 59 |
+
|
|
|
|
| 60 |
model = Mistral3ForConditionalGeneration.from_pretrained(
|
| 61 |
MODEL_ID,
|
| 62 |
dtype=torch.bfloat16,
|
| 63 |
device_map="auto",
|
| 64 |
)
|
| 65 |
+
|
| 66 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
| 67 |
+
MODEL_ID,
|
| 68 |
+
trust_remote_code=True,
|
| 69 |
+
tokenizer_type="mistral",
|
| 70 |
+
use_fast=False,
|
| 71 |
+
)
|
| 72 |
+
if tokenizer.pad_token is None:
|
| 73 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 74 |
+
|
| 75 |
print("Model loaded successfully")
|
| 76 |
+
return model, tokenizer
|
| 77 |
|
| 78 |
|
| 79 |
# Initialize on startup
|
| 80 |
download_spacy_models()
|
| 81 |
+
model, tokenizer = load_model()
|
| 82 |
nlp_cache: dict[str, spacy.Language] = {}
|
| 83 |
|
| 84 |
|
|
|
|
| 323 |
"""Generate summary with streaming output."""
|
| 324 |
tagged_text, tag_to_sentence, tag_to_pos = tag_sentences(text, lang_code)
|
| 325 |
num_sentences = len(tag_to_sentence)
|
| 326 |
+
|
| 327 |
prompt = build_prompt(tagged_text, words, language_name, custom_instruction)
|
| 328 |
messages = [{"role": "user", "content": prompt}]
|
| 329 |
+
inputs = tokenizer.apply_chat_template(
|
| 330 |
+
messages,
|
| 331 |
+
return_tensors="pt",
|
| 332 |
+
add_generation_prompt=True,
|
| 333 |
+
).to(model.device)
|
| 334 |
|
| 335 |
+
streamer = TextIteratorStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
|
| 336 |
|
| 337 |
gen_kwargs = {
|
| 338 |
"input_ids": inputs,
|
| 339 |
"streamer": streamer,
|
| 340 |
"max_new_tokens": 4096,
|
| 341 |
"do_sample": False,
|
| 342 |
+
"pad_token_id": tokenizer.pad_token_id,
|
| 343 |
}
|
| 344 |
|
| 345 |
thread = Thread(target=model.generate, kwargs=gen_kwargs)
|
|
|
|
| 462 |
max-width: 1200px !important;
|
| 463 |
margin: 0 auto !important;
|
| 464 |
padding: 1.5rem 2rem !important;
|
| 465 |
+
overflow: visible !important;
|
| 466 |
+
}
|
| 467 |
+
|
| 468 |
+
/* Prevent parent elements from clipping corners */
|
| 469 |
+
.gradio-container > div,
|
| 470 |
+
.gradio-row,
|
| 471 |
+
.contain,
|
| 472 |
+
.gap {
|
| 473 |
+
overflow: visible !important;
|
| 474 |
}
|
| 475 |
|
| 476 |
/* Header styling */
|
|
|
|
| 503 |
border-radius: 0.75rem !important;
|
| 504 |
border: 1px solid #e2e8f0 !important;
|
| 505 |
padding: 1rem !important;
|
| 506 |
+
overflow: visible !important;
|
| 507 |
}
|
| 508 |
|
| 509 |
.output-panel {
|
|
|
|
| 512 |
border: 1px solid #e2e8f0 !important;
|
| 513 |
padding: 1rem !important;
|
| 514 |
min-height: 300px;
|
| 515 |
+
overflow: visible !important;
|
| 516 |
}
|
| 517 |
|
| 518 |
/* Section headers - simpler, not uppercase */
|