Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -3,17 +3,16 @@ from dotenv import load_dotenv
|
|
3 |
from transformers import TFBertForSequenceClassification, BertTokenizerFast
|
4 |
import tensorflow as tf
|
5 |
|
6 |
-
#
|
7 |
-
|
8 |
-
API_KEY = "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"
|
9 |
|
10 |
-
def load_model(
|
11 |
# Load the TensorFlow model from Hugging Face Hub
|
12 |
-
model = TFBertForSequenceClassification.from_pretrained(model_name, use_auth_token=
|
13 |
return model
|
14 |
|
15 |
-
def load_tokenizer(
|
16 |
-
tokenizer = BertTokenizerFast.from_pretrained(model_name, use_auth_token=
|
17 |
return tokenizer
|
18 |
|
19 |
def predict(text, model, tokenizer):
|
@@ -22,8 +21,8 @@ def predict(text, model, tokenizer):
|
|
22 |
return outputs
|
23 |
|
24 |
def main():
|
25 |
-
model_name =
|
26 |
-
model = load_model(
|
27 |
tokenizer = load_tokenizer(model_name)
|
28 |
# Example usage
|
29 |
text = "Sample input text"
|
|
|
3 |
from transformers import TFBertForSequenceClassification, BertTokenizerFast
|
4 |
import tensorflow as tf
|
5 |
|
6 |
+
# Load environment variables from .env file
|
7 |
+
load_dotenv()
|
|
|
8 |
|
9 |
+
def load_model(model_name):
|
10 |
# Load the TensorFlow model from Hugging Face Hub
|
11 |
+
model = TFBertForSequenceClassification.from_pretrained(model_name, use_auth_token=os.getenv('API_KEY'))
|
12 |
return model
|
13 |
|
14 |
+
def load_tokenizer(model_name):
|
15 |
+
tokenizer = BertTokenizerFast.from_pretrained(model_name, use_auth_token=os.getenv('API_KEY'))
|
16 |
return tokenizer
|
17 |
|
18 |
def predict(text, model, tokenizer):
|
|
|
21 |
return outputs
|
22 |
|
23 |
def main():
|
24 |
+
model_name = os.getenv('MODEL_PATH')
|
25 |
+
model = load_model(model_name)
|
26 |
tokenizer = load_tokenizer(model_name)
|
27 |
# Example usage
|
28 |
text = "Sample input text"
|