Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
import torch.nn as nn
|
| 4 |
+
import pandas as pd
|
| 5 |
+
from PIL import Image
|
| 6 |
+
from transformers import BlipProcessor, BlipForConditionalGeneration, AutoTokenizer, AutoModel
|
| 7 |
+
|
| 8 |
+
# --- Load BLIP model ---
|
| 9 |
+
blip_path = "Models/blip_skin_cancer"
|
| 10 |
+
processor = BlipProcessor.from_pretrained(blip_path)
|
| 11 |
+
blip_model = BlipForConditionalGeneration.from_pretrained(blip_path).to("cpu")
|
| 12 |
+
|
| 13 |
+
# --- Load BioClinicalBERT + BiLSTM classifier ---
|
| 14 |
+
tokenizer = AutoTokenizer.from_pretrained("emilyalsentzer/Bio_ClinicalBERT")
|
| 15 |
+
bert_model = AutoModel.from_pretrained("emilyalsentzer/Bio_ClinicalBERT")
|
| 16 |
+
|
| 17 |
+
class BiLSTMClassifier(nn.Module):
|
| 18 |
+
def __init__(self, bert_model, hidden_dim=256, num_classes=7, dropout=0.5):
|
| 19 |
+
super().__init__()
|
| 20 |
+
self.bert = bert_model
|
| 21 |
+
self.lstm = nn.LSTM(768, hidden_dim, batch_first=True, bidirectional=True)
|
| 22 |
+
self.dropout = nn.Dropout(dropout)
|
| 23 |
+
self.fc = nn.Linear(hidden_dim*2, num_classes)
|
| 24 |
+
|
| 25 |
+
def forward(self, input_ids, attention_mask):
|
| 26 |
+
outputs = self.bert(input_ids=input_ids, attention_mask=attention_mask)
|
| 27 |
+
embeddings = outputs.last_hidden_state
|
| 28 |
+
lstm_out, _ = self.lstm(embeddings)
|
| 29 |
+
pooled = torch.mean(lstm_out, dim=1)
|
| 30 |
+
pooled = self.dropout
|