Update app.py
Browse files
app.py
CHANGED
|
@@ -1,59 +1,59 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from pubmed_rag import search_pubmed, fetch_pubmed_abstracts, summarize_text
|
| 3 |
from image_pipeline import analyze_medical_image
|
| 4 |
-
from models import
|
|
|
|
| 5 |
|
| 6 |
st.set_page_config(page_title="Advanced Medical AI", layout="wide")
|
| 7 |
|
| 8 |
-
|
| 9 |
def main():
|
| 10 |
st.title("Advanced Medical AI")
|
| 11 |
st.sidebar.title("Features")
|
| 12 |
task = st.sidebar.selectbox("Choose a task:", ["PubMed Q&A", "Medical Image Analysis"])
|
| 13 |
|
| 14 |
if task == "PubMed Q&A":
|
| 15 |
-
# PubMed
|
| 16 |
st.subheader("PubMed Question Answering")
|
| 17 |
query = st.text_input("Enter your medical question:", "What are the latest treatments for diabetes?")
|
| 18 |
max_results = st.slider("Number of PubMed articles to retrieve:", 1, 10, 5)
|
| 19 |
|
| 20 |
if st.button("Run Query"):
|
| 21 |
with st.spinner("Searching PubMed..."):
|
|
|
|
| 22 |
pmids = search_pubmed(query, max_results)
|
| 23 |
if not pmids:
|
| 24 |
st.error("No results found. Try another query.")
|
| 25 |
return
|
| 26 |
|
| 27 |
with st.spinner("Fetching and summarizing abstracts..."):
|
|
|
|
| 28 |
abstracts = fetch_pubmed_abstracts(pmids)
|
|
|
|
| 29 |
summaries = {pmid: summarize_text(abstract) for pmid, abstract in abstracts.items()}
|
| 30 |
|
| 31 |
st.subheader("PubMed Summaries")
|
| 32 |
for pmid, summary in summaries.items():
|
| 33 |
st.write(f"**PMID {pmid}**: {summary}")
|
| 34 |
|
| 35 |
-
with st.spinner("Querying
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
| 37 |
st.subheader("AI-Powered Answer")
|
| 38 |
st.write(answer)
|
| 39 |
|
| 40 |
elif task == "Medical Image Analysis":
|
| 41 |
-
# Medical Image Analysis
|
| 42 |
st.subheader("Medical Image Analysis")
|
| 43 |
uploaded_file = st.file_uploader("Upload a medical image (PNG/JPG):", type=["png", "jpg", "jpeg"])
|
| 44 |
-
|
| 45 |
if uploaded_file:
|
| 46 |
-
# Display the uploaded image
|
| 47 |
st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
|
| 48 |
-
|
| 49 |
-
# Analyze the medical image
|
| 50 |
with st.spinner("Analyzing image..."):
|
|
|
|
| 51 |
result = analyze_medical_image(uploaded_file)
|
| 52 |
-
|
| 53 |
-
# Display the result
|
| 54 |
st.subheader("Diagnostic Insight")
|
| 55 |
st.write(result)
|
| 56 |
|
| 57 |
-
|
| 58 |
if __name__ == "__main__":
|
| 59 |
main()
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from pubmed_rag import search_pubmed, fetch_pubmed_abstracts, summarize_text
|
| 3 |
from image_pipeline import analyze_medical_image
|
| 4 |
+
from models import query_openai_text
|
| 5 |
+
from config import OPENAI_DEFAULT_MODEL
|
| 6 |
|
| 7 |
st.set_page_config(page_title="Advanced Medical AI", layout="wide")
|
| 8 |
|
|
|
|
| 9 |
def main():
|
| 10 |
st.title("Advanced Medical AI")
|
| 11 |
st.sidebar.title("Features")
|
| 12 |
task = st.sidebar.selectbox("Choose a task:", ["PubMed Q&A", "Medical Image Analysis"])
|
| 13 |
|
| 14 |
if task == "PubMed Q&A":
|
| 15 |
+
# PubMed Question Answering
|
| 16 |
st.subheader("PubMed Question Answering")
|
| 17 |
query = st.text_input("Enter your medical question:", "What are the latest treatments for diabetes?")
|
| 18 |
max_results = st.slider("Number of PubMed articles to retrieve:", 1, 10, 5)
|
| 19 |
|
| 20 |
if st.button("Run Query"):
|
| 21 |
with st.spinner("Searching PubMed..."):
|
| 22 |
+
# Step 1: Search PubMed
|
| 23 |
pmids = search_pubmed(query, max_results)
|
| 24 |
if not pmids:
|
| 25 |
st.error("No results found. Try another query.")
|
| 26 |
return
|
| 27 |
|
| 28 |
with st.spinner("Fetching and summarizing abstracts..."):
|
| 29 |
+
# Step 2: Fetch abstracts
|
| 30 |
abstracts = fetch_pubmed_abstracts(pmids)
|
| 31 |
+
# Step 3: Summarize abstracts
|
| 32 |
summaries = {pmid: summarize_text(abstract) for pmid, abstract in abstracts.items()}
|
| 33 |
|
| 34 |
st.subheader("PubMed Summaries")
|
| 35 |
for pmid, summary in summaries.items():
|
| 36 |
st.write(f"**PMID {pmid}**: {summary}")
|
| 37 |
|
| 38 |
+
with st.spinner("Querying OpenAI model..."):
|
| 39 |
+
# Step 4: Query OpenAI model with summarized abstracts
|
| 40 |
+
system_message = "You are a medical assistant with access to summarized PubMed abstracts."
|
| 41 |
+
user_message = f"Summarized articles: {summaries}\n\nQuestion: {query}"
|
| 42 |
+
answer = query_openai_text(system_message, user_message, OPENAI_DEFAULT_MODEL)
|
| 43 |
st.subheader("AI-Powered Answer")
|
| 44 |
st.write(answer)
|
| 45 |
|
| 46 |
elif task == "Medical Image Analysis":
|
| 47 |
+
# Medical Image Analysis
|
| 48 |
st.subheader("Medical Image Analysis")
|
| 49 |
uploaded_file = st.file_uploader("Upload a medical image (PNG/JPG):", type=["png", "jpg", "jpeg"])
|
|
|
|
| 50 |
if uploaded_file:
|
|
|
|
| 51 |
st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
|
|
|
|
|
|
|
| 52 |
with st.spinner("Analyzing image..."):
|
| 53 |
+
# Step 1: Analyze the uploaded image
|
| 54 |
result = analyze_medical_image(uploaded_file)
|
|
|
|
|
|
|
| 55 |
st.subheader("Diagnostic Insight")
|
| 56 |
st.write(result)
|
| 57 |
|
|
|
|
| 58 |
if __name__ == "__main__":
|
| 59 |
main()
|