Fredaaaaaa commited on
Commit
0be1c7b
·
verified ·
1 Parent(s): 3248144

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +24 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 = "Fredaaaaaa/biobert_model" # 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()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ transformers
2
+ torch
3
+ gradio