Spaces:
Runtime error
Runtime error
updated model weights path
Browse files
app.py
CHANGED
|
@@ -6,31 +6,13 @@ import gradio as gr
|
|
| 6 |
from transformers import BertTokenizer, BertForSequenceClassification
|
| 7 |
import os
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
-
if not os.path.exists('BioBERT_Model'):
|
| 15 |
-
with zipfile.ZipFile(model_zip_path, 'r') as zip_ref:
|
| 16 |
-
zip_ref.extractall('BioBERT_Model')
|
| 17 |
|
| 18 |
-
if not os.path.exists('BioBERT_Tokenizer'):
|
| 19 |
-
with zipfile.ZipFile(tokenizer_zip_path, 'r') as zip_ref:
|
| 20 |
-
zip_ref.extractall('BioBERT_Tokenizer')
|
| 21 |
-
|
| 22 |
-
model_path = 'BioBERT_Model/content/BioBERT_Model'
|
| 23 |
-
tokenizer_path = 'BioBERT_Tokenizer/content/BioBERT_Tokenizer'
|
| 24 |
-
|
| 25 |
-
model = BertForSequenceClassification.from_pretrained(model_path)
|
| 26 |
-
tokenizer = BertTokenizer.from_pretrained(tokenizer_path)
|
| 27 |
-
|
| 28 |
-
return model, tokenizer
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
model, tokenizer = load_model_and_tokenizer()
|
| 32 |
device = "cpu"
|
| 33 |
-
model = model.to(device)
|
| 34 |
|
| 35 |
def predict_drug_target_interaction(sentence):
|
| 36 |
# Tokenize the input sentence
|
|
|
|
| 6 |
from transformers import BertTokenizer, BertForSequenceClassification
|
| 7 |
import os
|
| 8 |
|
| 9 |
+
tokenizer = BertTokenizer.from_pretrained("dmis-lab/biobert-base-cased-v1.1")
|
| 10 |
+
model = BertForSequenceClassification.from_pretrained("dmis-lab/biobert-base-cased-v1.1", num_labels=2)
|
| 11 |
|
| 12 |
+
# loading the pretrained weights into the model
|
| 13 |
+
model.load_state_dict(torch.load('Bio_BERT_model.pth'))
|
|
|
|
|
|
|
|
|
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
device = "cpu"
|
|
|
|
| 16 |
|
| 17 |
def predict_drug_target_interaction(sentence):
|
| 18 |
# Tokenize the input sentence
|