Update app.py
Browse files
app.py
CHANGED
|
@@ -1,39 +1,21 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import BertTokenizer, BertForSequenceClassification
|
| 3 |
import torch
|
| 4 |
import pickle
|
| 5 |
-
import requests
|
| 6 |
from collections import defaultdict
|
| 7 |
import random
|
| 8 |
import os
|
| 9 |
|
| 10 |
-
# GitHub-dan label_encoder yükləmək
|
| 11 |
-
def download_label_encoder():
|
| 12 |
-
url = "https://github.com/AxundovReyal/nlp-disease/raw/main/label_encoder.pkl"
|
| 13 |
-
headers = {}
|
| 14 |
-
github_token = os.getenv("GITHUB_TOKEN")
|
| 15 |
-
if github_token:
|
| 16 |
-
headers["Authorization"] = f"token {github_token}"
|
| 17 |
-
|
| 18 |
-
response = requests.get(url, headers=headers)
|
| 19 |
-
if response.status_code == 200:
|
| 20 |
-
with open("label_encoder.pkl", "wb") as f:
|
| 21 |
-
f.write(response.content)
|
| 22 |
-
print("label_encoder.pkl faylı uğurla yükləndi.")
|
| 23 |
-
else:
|
| 24 |
-
raise Exception(f"Fayl yüklənə bilmədi, error kodu: {response.status_code}")
|
| 25 |
-
|
| 26 |
# Model və label_encoder yüklənməsi
|
| 27 |
def load_model():
|
| 28 |
-
|
| 29 |
-
with open("label_encoder.pkl", "rb") as f:
|
| 30 |
label_encoder = pickle.load(f)
|
| 31 |
|
| 32 |
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
model.eval()
|
| 38 |
return tokenizer, model, label_encoder
|
| 39 |
|
|
@@ -81,4 +63,4 @@ iface = gr.Interface(
|
|
| 81 |
|
| 82 |
# Launch
|
| 83 |
if __name__ == "__main__":
|
| 84 |
-
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, BertConfig
|
| 3 |
import torch
|
| 4 |
import pickle
|
|
|
|
| 5 |
from collections import defaultdict
|
| 6 |
import random
|
| 7 |
import os
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
# Model və label_encoder yüklənməsi
|
| 10 |
def load_model():
|
| 11 |
+
with open("best_model/label_encoder.pkl", "rb") as f:
|
|
|
|
| 12 |
label_encoder = pickle.load(f)
|
| 13 |
|
| 14 |
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
|
| 15 |
+
|
| 16 |
+
config = BertConfig.from_pretrained('bert-base-uncased', num_labels=len(label_encoder.classes_))
|
| 17 |
+
model = BertForSequenceClassification.from_pretrained('bert-base-uncased', config=config)
|
| 18 |
+
|
| 19 |
model.eval()
|
| 20 |
return tokenizer, model, label_encoder
|
| 21 |
|
|
|
|
| 63 |
|
| 64 |
# Launch
|
| 65 |
if __name__ == "__main__":
|
| 66 |
+
iface.launch(server_name="0.0.0.0", server_port=int(os.environ.get("PORT", 7860)), debug=True)
|