Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import BertTokenizer, BertForSequenceClassification
|
| 3 |
import torch
|
| 4 |
import pickle
|
| 5 |
from collections import defaultdict
|
|
@@ -13,22 +13,14 @@ def load_model():
|
|
| 13 |
label_encoder = pickle.load(f)
|
| 14 |
|
| 15 |
# Tokenizer
|
| 16 |
-
tokenizer = BertTokenizer.from_pretrained(
|
| 17 |
-
|
| 18 |
-
# Config
|
| 19 |
-
config = BertConfig.from_pretrained('bert-base-uncased', num_labels=len(label_encoder.classes_))
|
| 20 |
-
|
| 21 |
-
# Model
|
| 22 |
-
model = BertForSequenceClassification(config)
|
| 23 |
-
|
| 24 |
-
# Safetensors faylını yükləyirik
|
| 25 |
-
state_dict = load_file("best_model/model.safetensors")
|
| 26 |
-
model.load_state_dict(state_dict)
|
| 27 |
|
|
|
|
|
|
|
| 28 |
model.eval()
|
|
|
|
| 29 |
return tokenizer, model, label_encoder
|
| 30 |
|
| 31 |
-
|
| 32 |
tokenizer, model, label_encoder = load_model()
|
| 33 |
|
| 34 |
# Prediction funksiyası
|
|
@@ -73,4 +65,4 @@ iface = gr.Interface(
|
|
| 73 |
|
| 74 |
# Launch
|
| 75 |
if __name__ == "__main__":
|
| 76 |
-
iface.launch(server_name="0.0.0.0", server_port=int(os.environ.get("PORT", 7860))
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import BertTokenizer, BertForSequenceClassification
|
| 3 |
import torch
|
| 4 |
import pickle
|
| 5 |
from collections import defaultdict
|
|
|
|
| 13 |
label_encoder = pickle.load(f)
|
| 14 |
|
| 15 |
# Tokenizer
|
| 16 |
+
tokenizer = BertTokenizer.from_pretrained("best_model")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
# Model (safetensors avtomatik dəstəklənir)
|
| 19 |
+
model = BertForSequenceClassification.from_pretrained("best_model", use_safetensors=True)
|
| 20 |
model.eval()
|
| 21 |
+
|
| 22 |
return tokenizer, model, label_encoder
|
| 23 |
|
|
|
|
| 24 |
tokenizer, model, label_encoder = load_model()
|
| 25 |
|
| 26 |
# Prediction funksiyası
|
|
|
|
| 65 |
|
| 66 |
# Launch
|
| 67 |
if __name__ == "__main__":
|
| 68 |
+
iface.launch(server_name="0.0.0.0", server_port=int(os.environ.get("PORT", 7860)))
|