amine_dubs
commited on
Commit
·
068c749
1
Parent(s):
c38e2fa
Implement transformers library with T5 model and custom Arabic prompt
Browse files- backend/main.py +4 -2
backend/main.py
CHANGED
@@ -63,20 +63,22 @@ def initialize_model():
|
|
63 |
# Use a smaller model that works well for instruction-based translation
|
64 |
model_name = "google/flan-t5-small"
|
65 |
|
66 |
-
# Load the
|
67 |
tokenizer = AutoTokenizer.from_pretrained(
|
68 |
model_name,
|
69 |
cache_dir="/tmp/transformers_cache"
|
70 |
)
|
71 |
|
72 |
# Create a pipeline for text2text generation
|
|
|
73 |
translator = pipeline(
|
74 |
"text2text-generation",
|
75 |
model=model_name,
|
76 |
tokenizer=tokenizer,
|
77 |
device=-1, # Use CPU for compatibility (-1) or GPU if available (0)
|
78 |
cache_dir="/tmp/transformers_cache",
|
79 |
-
max_length=512
|
|
|
80 |
)
|
81 |
|
82 |
print(f"Model {model_name} successfully initialized")
|
|
|
63 |
# Use a smaller model that works well for instruction-based translation
|
64 |
model_name = "google/flan-t5-small"
|
65 |
|
66 |
+
# Load the tokenizer with explicit cache directory
|
67 |
tokenizer = AutoTokenizer.from_pretrained(
|
68 |
model_name,
|
69 |
cache_dir="/tmp/transformers_cache"
|
70 |
)
|
71 |
|
72 |
# Create a pipeline for text2text generation
|
73 |
+
# Important: Add from_tf=True to load TensorFlow weights
|
74 |
translator = pipeline(
|
75 |
"text2text-generation",
|
76 |
model=model_name,
|
77 |
tokenizer=tokenizer,
|
78 |
device=-1, # Use CPU for compatibility (-1) or GPU if available (0)
|
79 |
cache_dir="/tmp/transformers_cache",
|
80 |
+
max_length=512,
|
81 |
+
model_kwargs={"from_tf": True} # This is the key fix
|
82 |
)
|
83 |
|
84 |
print(f"Model {model_name} successfully initialized")
|