Spaces:
Sleeping
Sleeping
File size: 1,261 Bytes
9d79421 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
import streamlit as st
from transformers import pipeline
import os
# Load the Hugging Face access token from secrets
access_token = os.getenv("HF_TOKEN") # Token is securely retrieved from secrets
# Model name
MODEL_NAME = "Alaaeldin/pubmedBERT-demo"
@st.cache_resource
def load_pipeline():
return pipeline("question-answering", model=MODEL_NAME, tokenizer=MODEL_NAME, use_auth_token=access_token)
# Load the pipeline
qa_pipeline = load_pipeline()
# Streamlit app UI
st.title("PubMed BERT Q&A App")
st.write("Ask questions based on biomedical content!")
# User inputs
context = st.text_area("Enter the biomedical context (e.g., PubMed abstract):", height=200)
question = st.text_input("Enter your question:")
# Button to get the answer
if st.button("Get Answer"):
if context.strip() and question.strip():
with st.spinner("Finding the answer..."):
result = qa_pipeline(question=question, context=context)
st.success(f"Answer: {result['answer']}")
st.write(f"Confidence: {result['score']:.2f}")
else:
st.warning("Please provide both context and a question.")
# Footer
st.markdown("---")
st.markdown("Powered by **PubMed BERT** fine-tuned by [Alaaeldin](https://huggingface.co/Alaaeldin).")
|