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