Pujan-Dev commited on
Commit
2cca8fd
·
verified ·
1 Parent(s): d60213d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -12
app.py CHANGED
@@ -29,22 +29,21 @@ def verify_token(auth: str):
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
 
49
  @asynccontextmanager
50
  async def lifespan(app: FastAPI):
 
29
  # Function to load model and tokenizer
30
 
31
  def load_model():
 
32
  model_path = "./Ai-Text-Detector/model"
 
 
 
 
 
 
33
  weights_path = "./Ai-Text-Detector/model_weights.pth"
34
+
35
+ # Load tokenizer and config from your custom model path
36
+ tokenizer = GPT2TokenizerFast.from_pretrained(model_path)
37
+ config = GPT2Config.from_pretrained(model_path)
38
+
39
+ # Initialize model from config (don't load any weights from Hugging Face)
40
+ model = GPT2LMHeadModel(config)
41
+
42
+ # Load your saved PyTorch weights
43
  model.load_state_dict(torch.load(weights_path, map_location=torch.device("cpu")))
 
 
 
 
 
44
 
45
+ model.eval() # Set to evaluation mode
46
+ return model, tokenizer
47
 
48
  @asynccontextmanager
49
  async def lifespan(app: FastAPI):