meghnabjayakar commited on
Commit
2826344
·
verified ·
1 Parent(s): d2fc15d

trial for docker unzipping

Browse files
Files changed (1) hide show
  1. app.py +27 -1
app.py CHANGED
@@ -1,10 +1,36 @@
1
  import torch
2
  import torch.nn.functional as F # Importing the functional module for softmax
3
  from torch import nn
 
4
  import gradio as gr
 
5
  import os
6
 
 
 
 
7
  # Assume model and tokenizer are already loaded
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  def predict_drug_target_interaction(sentence):
10
  # Tokenize the input sentence
@@ -155,4 +181,4 @@ with gr.Blocks() as demo:
155
 
156
 
157
  # Launch the interface
158
- demo.launch()
 
1
  import torch
2
  import torch.nn.functional as F # Importing the functional module for softmax
3
  from torch import nn
4
+ import zipfile
5
  import gradio as gr
6
+ from transformers import BertTokenizer, BertForSequenceClassification
7
  import os
8
 
9
+ model_zip_path = "BioBERT_Model.zip"
10
+ tokenizer_zip_path = "BioBERT_Tokenizer.zip"
11
+
12
  # Assume model and tokenizer are already loaded
13
+ def load_model_and_tokenizer():
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
 
181
 
182
 
183
  # Launch the interface
184
+ demo.launch()