Spaces:
Sleeping
Sleeping
Commit
·
2409ded
1
Parent(s):
c74b7a2
add change models loading
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import gradio as gr
|
|
| 2 |
import os
|
| 3 |
import ctranslate2
|
| 4 |
from transformers import M2M100Tokenizer
|
|
|
|
| 5 |
import time
|
| 6 |
|
| 7 |
# Model settings
|
|
@@ -12,9 +13,15 @@ TOKENIZER_PATH = os.getenv("TOKENIZER_PATH", "skypro1111/m2m100-ukr-verbalizatio
|
|
| 12 |
def init_model(model_path=MODEL_PATH, tokenizer_path=TOKENIZER_PATH):
|
| 13 |
print("\nInitializing CTranslate2 model and tokenizer...")
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
# Initialize translator with optimizations for CPU
|
| 16 |
translator = ctranslate2.Translator(
|
| 17 |
-
|
| 18 |
device="cpu",
|
| 19 |
compute_type="int8", # Use INT8 quantization for CPU
|
| 20 |
intra_threads=4, # Adjust based on CPU cores available
|
|
|
|
| 2 |
import os
|
| 3 |
import ctranslate2
|
| 4 |
from transformers import M2M100Tokenizer
|
| 5 |
+
from huggingface_hub import snapshot_download
|
| 6 |
import time
|
| 7 |
|
| 8 |
# Model settings
|
|
|
|
| 13 |
def init_model(model_path=MODEL_PATH, tokenizer_path=TOKENIZER_PATH):
|
| 14 |
print("\nInitializing CTranslate2 model and tokenizer...")
|
| 15 |
|
| 16 |
+
# Download the model from HuggingFace Hub
|
| 17 |
+
local_model_path = snapshot_download(
|
| 18 |
+
repo_id=model_path,
|
| 19 |
+
allow_patterns=["*.bin", "*.json", "tokenizer.json", "vocab.json"],
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
# Initialize translator with optimizations for CPU
|
| 23 |
translator = ctranslate2.Translator(
|
| 24 |
+
local_model_path,
|
| 25 |
device="cpu",
|
| 26 |
compute_type="int8", # Use INT8 quantization for CPU
|
| 27 |
intra_threads=4, # Adjust based on CPU cores available
|