Pujan-Dev commited on
Commit
d60213d
·
verified ·
1 Parent(s): 3f36270

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -4
app.py CHANGED
@@ -28,14 +28,21 @@ def verify_token(auth: str):
28
 
29
  # Function to load model and tokenizer
30
 
31
-
32
  def load_model():
 
33
  model_path = "./Ai-Text-Detector/model"
34
- weights_path = "./Ai-Text-Detector/model_weights.pth"
35
  tokenizer = GPT2TokenizerFast.from_pretrained(model_path)
36
- model = GPT2LMHeadModel.from_pretrained("gpt2",from_tf=True)
 
 
 
 
 
37
  model.load_state_dict(torch.load(weights_path, map_location=torch.device("cpu")))
38
- model.eval() # Set the model to evaluation mode
 
 
 
39
  return model, tokenizer
40
 
41
 
 
28
 
29
  # Function to load model and tokenizer
30
 
 
31
  def load_model():
32
+ # Load tokenizer from the specified path
33
  model_path = "./Ai-Text-Detector/model"
 
34
  tokenizer = GPT2TokenizerFast.from_pretrained(model_path)
35
+
36
+ # Load the GPT-2 model (without loading weights initially)
37
+ model = GPT2LMHeadModel.from_pretrained("gpt2", config=model_path)
38
+
39
+ # Load the custom weights from the local .pth file
40
+ weights_path = "./Ai-Text-Detector/model_weights.pth"
41
  model.load_state_dict(torch.load(weights_path, map_location=torch.device("cpu")))
42
+
43
+ # Set the model to evaluation mode
44
+ model.eval()
45
+
46
  return model, tokenizer
47
 
48