Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import AutoTokenizer, AutoModelForSequenceClassification | |
| import torch | |
| # ✅ Load from current directory where files are | |
| model_path = "." | |
| tokenizer = AutoTokenizer.from_pretrained(model_path) | |
| model = AutoModelForSequenceClassification.from_pretrained(model_path) | |
| def predict(text): | |
| inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True) | |
| with torch.no_grad(): | |
| outputs = model(**inputs) | |
| pred = torch.argmax(outputs.logits, dim=1).item() | |
| return ["No interaction", "Mild", "Moderate", "Severe"][pred] | |
| demo = gr.Interface(fn=predict, inputs="text", outputs="text", title="BioBERT Drug Interaction Predictor") | |
| demo.launch() | |