MissingBreath commited on
Commit
7fb86a3
·
verified ·
1 Parent(s): 86e19c1

Update api.py

Browse files
Files changed (1) hide show
  1. api.py +20 -8
api.py CHANGED
@@ -4,7 +4,7 @@ from PIL import Image
4
  import io
5
  import tensorflow as tf
6
  import os
7
- from transformers import AutoTokenizer, AutoModelForSequenceClassification
8
  # # os.environ['HF_TOKEN']=''
9
  # from huggingface_hub import login
10
 
@@ -13,14 +13,14 @@ from transformers import AutoTokenizer, AutoModelForSequenceClassification
13
 
14
 
15
  # Read token from environment
16
- hf_token = os.getenv("HF_TOKEN")
17
- print("HF_TOKEN:", hf_token)
18
 
19
  # Load tokenizer directly with the token (no login)
20
- tokenizer = AutoTokenizer.from_pretrained(
21
- "chillies/distilbert-course-review-classification",
22
- token=hf_token # Pass it directly
23
- )
24
 
25
 
26
 
@@ -30,7 +30,7 @@ tokenizer = AutoTokenizer.from_pretrained(
30
  # tokenizer = DistilBertTokenizer.from_pretrained("distilbert-base-uncased")
31
 
32
 
33
- model = AutoModelForSequenceClassification.from_pretrained("chillies/distilbert-course-review-classification")
34
 
35
 
36
  # from transformers import DistilBertTokenizerFast
@@ -42,6 +42,18 @@ model = AutoModelForSequenceClassification.from_pretrained("chillies/distilbert-
42
  # model = pipeline("text-classification", model="distilbert-base-uncased-finetuned-sst-2-english")
43
 
44
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
  def inference(review):
47
  inputs = tokenizer(review, return_tensors="pt", padding=True, truncation=True)
 
4
  import io
5
  import tensorflow as tf
6
  import os
7
+ # from transformers import AutoTokenizer, AutoModelForSequenceClassification
8
  # # os.environ['HF_TOKEN']=''
9
  # from huggingface_hub import login
10
 
 
13
 
14
 
15
  # Read token from environment
16
+ # hf_token = os.getenv("HF_TOKEN")
17
+ # print("HF_TOKEN:", hf_token)
18
 
19
  # Load tokenizer directly with the token (no login)
20
+ # tokenizer = AutoTokenizer.from_pretrained(
21
+ # "chillies/distilbert-course-review-classification",
22
+ # token=hf_token # Pass it directly
23
+ # )
24
 
25
 
26
 
 
30
  # tokenizer = DistilBertTokenizer.from_pretrained("distilbert-base-uncased")
31
 
32
 
33
+ # model = AutoModelForSequenceClassification.from_pretrained("chillies/distilbert-course-review-classification")
34
 
35
 
36
  # from transformers import DistilBertTokenizerFast
 
42
  # model = pipeline("text-classification", model="distilbert-base-uncased-finetuned-sst-2-english")
43
 
44
 
45
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
46
+ MODEL_DIR = "/my_model"
47
+ TOKENIZER_DIR = "/my_tokenizer"
48
+ # Load the model and tokenizer
49
+ try:
50
+ model = AutoModelForSequenceClassification.from_pretrained(MODEL_DIR)
51
+ tokenizer = AutoTokenizer.from_pretrained(TOKENIZER_DIR)
52
+ print("Model and tokenizer loaded successfully.")
53
+ except Exception as e:
54
+ print(f"Error loading model or tokenizer: {e}")
55
+
56
+
57
 
58
  def inference(review):
59
  inputs = tokenizer(review, return_tensors="pt", padding=True, truncation=True)