Erfan11 commited on
Commit
42a8463
1 Parent(s): 67bc86d

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +8 -9
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
- # Directly specify model and API key
7
- MODEL_NAME = "Erfan11/Neuracraft"
8
- API_KEY = "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"
9
 
10
- def load_model(Erfan11/Neuracraft):
11
  # Load the TensorFlow model from Hugging Face Hub
12
- model = TFBertForSequenceClassification.from_pretrained(model_name, use_auth_token=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)
13
  return model
14
 
15
- def load_tokenizer(Erfan11/Neuracraft):
16
- tokenizer = BertTokenizerFast.from_pretrained(model_name, use_auth_token=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)
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 = Erfan11/Neuracraft
26
- model = load_model(Erfan11/Neuracraft)
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"