Erfan11 commited on
Commit
da70a87
1 Parent(s): a191194

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -12
app.py CHANGED
@@ -1,22 +1,17 @@
1
  import os
2
- from dotenv import load_dotenv
3
  from transformers import TFBertForSequenceClassification, BertTokenizerFast
4
- import tensorflow as tf
5
-
6
- # Load environment variables
7
- load_dotenv()
8
 
9
  def load_model(model_name):
10
  try:
11
- # Try loading the model as a TensorFlow model
12
- model = TFBertForSequenceClassification.from_pretrained(model_name, use_auth_token=os.getenv('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'))
13
  except OSError:
14
- # If loading fails, assume it's a PyTorch model and use from_pt=True
15
- model = TFBertForSequenceClassification.from_pretrained(model_name, use_auth_token=os.getenv('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'), from_pt=True)
16
  return model
17
 
18
  def load_tokenizer(model_name):
19
- tokenizer = BertTokenizerFast.from_pretrained(model_name, use_auth_token=os.getenv('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'))
20
  return tokenizer
21
 
22
  def predict(text, model, tokenizer):
@@ -25,10 +20,13 @@ def predict(text, model, tokenizer):
25
  return outputs
26
 
27
  def main():
28
- model_name = os.getenv('Erfan11/Neuracraft')
 
 
29
  model = load_model(model_name)
30
  tokenizer = load_tokenizer(model_name)
31
- # Example usage
 
32
  text = "Sample input text"
33
  result = predict(text, model, tokenizer)
34
  print(result)
 
1
  import os
 
2
  from transformers import TFBertForSequenceClassification, BertTokenizerFast
 
 
 
 
3
 
4
  def load_model(model_name):
5
  try:
6
+ # Load TensorFlow model first
7
+ model = TFBertForSequenceClassification.from_pretrained(model_name, use_auth_token="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")
8
  except OSError:
9
+ # Fallback to PyTorch model if TensorFlow fails
10
+ model = TFBertForSequenceClassification.from_pretrained(model_name, use_auth_token="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", from_pt=True)
11
  return model
12
 
13
  def load_tokenizer(model_name):
14
+ tokenizer = BertTokenizerFast.from_pretrained(model_name, use_auth_token="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")
15
  return tokenizer
16
 
17
  def predict(text, model, tokenizer):
 
20
  return outputs
21
 
22
  def main():
23
+ # Replace 'Erfan11/Neuracraft' with the correct model path if necessary
24
+ model_name = "Erfan11/Neuracraft"
25
+
26
  model = load_model(model_name)
27
  tokenizer = load_tokenizer(model_name)
28
+
29
+ # Example prediction
30
  text = "Sample input text"
31
  result = predict(text, model, tokenizer)
32
  print(result)