abeimam commited on
Commit
7cd70ea
·
verified ·
1 Parent(s): 0d9d5a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -1,14 +1,14 @@
1
  import json
 
2
  import torch
3
  import torch.nn as nn
4
  import torch.nn.functional as F
5
- from fastapi import FastAPI, HTTPException
6
  from pydantic import BaseModel
7
  from typing import List
8
- import math
9
 
10
  # ----------------------------
11
- # 1. Model definition (same as training)
12
  # ----------------------------
13
  class PositionalEncoding(nn.Module):
14
  def __init__(self, d_model: int, max_len: int = 512, dropout: float = 0.1):
@@ -54,7 +54,7 @@ class PhishingTransformer(nn.Module):
54
  return self.head(x)
55
 
56
  # ----------------------------
57
- # 2. Tokenizer (same as training)
58
  # ----------------------------
59
  class CharTokenizer:
60
  def __init__(self, max_len: int, char2id: dict):
@@ -73,9 +73,11 @@ class CharTokenizer:
73
  # ----------------------------
74
  with open("config.json", "r") as f:
75
  config = json.load(f)
 
76
  with open("tokenizer.json", "r") as f:
77
  tok_data = json.load(f)
78
  tokenizer = CharTokenizer(max_len=tok_data["max_len"], char2id=tok_data["char2id"])
 
79
  threshold = float(open("threshold.txt").read().strip())
80
 
81
  model = PhishingTransformer(config)
 
1
  import json
2
+ import math
3
  import torch
4
  import torch.nn as nn
5
  import torch.nn.functional as F
6
+ from fastapi import FastAPI
7
  from pydantic import BaseModel
8
  from typing import List
 
9
 
10
  # ----------------------------
11
+ # 1. Model definition (must match training)
12
  # ----------------------------
13
  class PositionalEncoding(nn.Module):
14
  def __init__(self, d_model: int, max_len: int = 512, dropout: float = 0.1):
 
54
  return self.head(x)
55
 
56
  # ----------------------------
57
+ # 2. Character tokenizer
58
  # ----------------------------
59
  class CharTokenizer:
60
  def __init__(self, max_len: int, char2id: dict):
 
73
  # ----------------------------
74
  with open("config.json", "r") as f:
75
  config = json.load(f)
76
+
77
  with open("tokenizer.json", "r") as f:
78
  tok_data = json.load(f)
79
  tokenizer = CharTokenizer(max_len=tok_data["max_len"], char2id=tok_data["char2id"])
80
+
81
  threshold = float(open("threshold.txt").read().strip())
82
 
83
  model = PhishingTransformer(config)