Fredaaaaaa commited on
Commit
8be8be5
·
verified ·
1 Parent(s): 6f57fb7

Upload 3 files

Browse files
Files changed (2) hide show
  1. app.py +11 -16
  2. biobert_model (2).zip +3 -0
app.py CHANGED
@@ -1,24 +1,19 @@
1
  import gradio as gr
2
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
  import torch
4
- import torch.nn.functional as F
5
-
6
- # Load model & tokenizer
7
- model_path = "./biobert" # or "your-username/your-model-name" if from Hugging Face Hub
8
- model = AutoModelForSequenceClassification.from_pretrained(model_path)
9
- tokenizer = AutoTokenizer.from_pretrained(model_path)
10
- model.eval()
11
 
 
 
12
 
 
 
13
 
14
- labels = ["No interaction", "Mild", "Moderate", "Severe"]
15
-
16
- def predict_interaction(text):
17
- encoding = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
18
  with torch.no_grad():
19
- outputs = model(**encoding)
20
- probs = F.softmax(outputs.logits, dim=1)
21
- pred = torch.argmax(probs, dim=1).item()
22
- return f"🧠 Prediction: {labels[pred]}"
23
 
24
- gr.Interface(fn=predict_interaction, inputs="text", outputs="text", title="Drug Interaction Predictor").launch()
 
 
1
  import gradio as gr
2
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
  import torch
 
 
 
 
 
 
 
4
 
5
+ # ✅ Load from current directory where files are
6
+ model_path = "."
7
 
8
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
9
+ model = AutoModelForSequenceClassification.from_pretrained(model_path)
10
 
11
+ def predict(text):
12
+ inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
 
 
13
  with torch.no_grad():
14
+ outputs = model(**inputs)
15
+ pred = torch.argmax(outputs.logits, dim=1).item()
16
+ return ["No interaction", "Mild", "Moderate", "Severe"][pred]
 
17
 
18
+ demo = gr.Interface(fn=predict, inputs="text", outputs="text", title="BioBERT Drug Interaction Predictor")
19
+ demo.launch()
biobert_model (2).zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6d71d2a2523c5cceb83cc93513beb47a5deebe0f451a2ae23b0963e002f4a13a
3
+ size 401868908