File size: 2,220 Bytes
8225d31
274d11f
fd2b30f
274d11f
8225d31
fd2b30f
8225d31
fd2b30f
274d11f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fd2b30f
 
 
 
8225d31
4b4bfa2
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
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 chat_with_openai

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":
        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..."):
                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..."):
                abstracts = fetch_pubmed_abstracts(pmids)
                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}")

            system_message = "You are a medical assistant with access to PubMed summaries."
            user_message = query
            with st.spinner("Generating answer..."):
                answer = chat_with_openai(system_message, user_message)
            st.subheader("AI-Powered Answer")
            st.write(answer)

    elif task == "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..."):
                result = analyze_medical_image(uploaded_file)
            st.subheader("Diagnostic Insight")
            st.write(result)

if __name__ == "__main__":
    main()