File size: 2,680 Bytes
8225d31
274d11f
fd2b30f
40f6d49
 
8225d31
fd2b30f
8225d31
fd2b30f
274d11f
 
 
 
 
40f6d49
274d11f
 
 
 
 
 
40f6d49
274d11f
 
 
 
 
 
40f6d49
274d11f
40f6d49
274d11f
 
 
 
 
 
40f6d49
 
 
 
 
274d11f
 
 
 
40f6d49
274d11f
 
 
 
 
40f6d49
fd2b30f
 
 
 
8225d31
ad06539
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import streamlit as st
from pubmed_rag import search_pubmed, fetch_pubmed_abstracts, summarize_text
from image_pipeline import analyze_medical_image
from models import query_openai_text
from config import OPENAI_DEFAULT_MODEL

st.set_page_config(page_title="Advanced Medical AI", layout="wide")

def main():
    st.title("Advanced Medical AI")
    st.sidebar.title("Features")
    task = st.sidebar.selectbox("Choose a task:", ["PubMed Q&A", "Medical Image Analysis"])

    if task == "PubMed Q&A":
        # PubMed Question Answering
        st.subheader("PubMed Question Answering")
        query = st.text_input("Enter your medical question:", "What are the latest treatments for diabetes?")
        max_results = st.slider("Number of PubMed articles to retrieve:", 1, 10, 5)

        if st.button("Run Query"):
            with st.spinner("Searching PubMed..."):
                # Step 1: Search PubMed
                pmids = search_pubmed(query, max_results)
                if not pmids:
                    st.error("No results found. Try another query.")
                    return

            with st.spinner("Fetching and summarizing abstracts..."):
                # Step 2: Fetch abstracts
                abstracts = fetch_pubmed_abstracts(pmids)
                # Step 3: Summarize abstracts
                summaries = {pmid: summarize_text(abstract) for pmid, abstract in abstracts.items()}

            st.subheader("PubMed Summaries")
            for pmid, summary in summaries.items():
                st.write(f"**PMID {pmid}**: {summary}")

            with st.spinner("Querying OpenAI model..."):
                # Step 4: Query OpenAI model with summarized abstracts
                system_message = "You are a medical assistant with access to summarized PubMed abstracts."
                user_message = f"Summarized articles: {summaries}\n\nQuestion: {query}"
                answer = query_openai_text(system_message, user_message, OPENAI_DEFAULT_MODEL)
            st.subheader("AI-Powered Answer")
            st.write(answer)

    elif task == "Medical Image Analysis":
        # Medical Image Analysis
        st.subheader("Medical Image Analysis")
        uploaded_file = st.file_uploader("Upload a medical image (PNG/JPG):", type=["png", "jpg", "jpeg"])
        if uploaded_file:
            st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
            with st.spinner("Analyzing image..."):
                # Step 1: Analyze the uploaded image
                result = analyze_medical_image(uploaded_file)
            st.subheader("Diagnostic Insight")
            st.write(result)

if __name__ == "__main__":
    main()