Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,14 +4,14 @@ from transformers import TFBertForSequenceClassification, BertTokenizerFast
|
|
4 |
def load_model(model_name):
|
5 |
try:
|
6 |
# Load TensorFlow model from Hugging Face
|
7 |
-
model = TFBertForSequenceClassification.from_pretrained(model_name, use_auth_token=os.getenv('
|
8 |
except OSError:
|
9 |
# Fallback to PyTorch model if TensorFlow fails
|
10 |
-
model = TFBertForSequenceClassification.from_pretrained(model_name, use_auth_token=os.getenv('
|
11 |
return model
|
12 |
|
13 |
def load_tokenizer(model_name):
|
14 |
-
tokenizer = BertTokenizerFast.from_pretrained(model_name, use_auth_token=os.getenv('
|
15 |
return tokenizer
|
16 |
|
17 |
def predict(text, model, tokenizer):
|
@@ -20,9 +20,9 @@ def predict(text, model, tokenizer):
|
|
20 |
return outputs
|
21 |
|
22 |
def main():
|
23 |
-
model_name = os.getenv('
|
24 |
if model_name is None:
|
25 |
-
raise ValueError("
|
26 |
|
27 |
model = load_model(model_name)
|
28 |
tokenizer = load_tokenizer(model_name)
|
|
|
4 |
def load_model(model_name):
|
5 |
try:
|
6 |
# Load TensorFlow model from Hugging Face
|
7 |
+
model = TFBertForSequenceClassification.from_pretrained(model_name, use_auth_token=os.getenv('API_KEY'))
|
8 |
except OSError:
|
9 |
# Fallback to PyTorch model if TensorFlow fails
|
10 |
+
model = TFBertForSequenceClassification.from_pretrained(model_name, use_auth_token=os.getenv('API_KEY'), from_pt=True)
|
11 |
return model
|
12 |
|
13 |
def load_tokenizer(model_name):
|
14 |
+
tokenizer = BertTokenizerFast.from_pretrained(model_name, use_auth_token=os.getenv('API_KEY'))
|
15 |
return tokenizer
|
16 |
|
17 |
def predict(text, model, tokenizer):
|
|
|
20 |
return outputs
|
21 |
|
22 |
def main():
|
23 |
+
model_name = os.getenv('MODEL_PATH')
|
24 |
if model_name is None:
|
25 |
+
raise ValueError("MODEL_PATH environment variable not set or is None")
|
26 |
|
27 |
model = load_model(model_name)
|
28 |
tokenizer = load_tokenizer(model_name)
|