|
import streamlit as st |
|
import joblib |
|
from sentence_transformers import SentenceTransformer |
|
|
|
|
|
@st.cache_resource |
|
def load_embedding_model(): |
|
return SentenceTransformer('neuml/pubmedbert-base-embeddings') |
|
|
|
|
|
@st.cache_resource |
|
def load_mlp_model(): |
|
with open("MLP.pkl", "rb") as file: |
|
return joblib.load(file) |
|
|
|
|
|
def get_embeddings(title, abstract, embedding_model): |
|
|
|
combined_text = title + " " + abstract |
|
return embedding_model.encode(combined_text) |
|
|
|
|
|
def main(): |
|
st.title("MLP Predictor for Titles and Abstracts") |
|
|
|
|
|
title = st.text_input("Enter the Title:") |
|
abstract = st.text_area("Enter the Abstract:") |
|
|
|
|
|
embedding_model = load_embedding_model() |
|
mlp_model = load_mlp_model() |
|
|
|
|
|
if st.button("Predict Label"): |
|
if title.strip() == "" or abstract.strip() == "": |
|
st.error("Both Title and Abstract are required!") |
|
else: |
|
|
|
embeddings = get_embeddings(title, abstract, embedding_model) |
|
|
|
|
|
prediction = mlp_model.predict([embeddings])[0] |
|
|
|
|
|
st.success(f"The predicted label is: {prediction}") |
|
|
|
if __name__ == "__main__": |
|
main() |
|
|