A conversational AI chatbot built with Streamlit and Google Gemini-Pro that provides medical information, analyzes uploaded medical reports (PDF), and intelligently filters medical queries to deliver relevant health insights.
π Medical Query Analysis Understands and responds to a wide range of medical-related queries.
Uses a built-in keyword detection system to ensure queries are medically relevant before providing AI-generated responses.
Filters out non-medical questions to maintain focused, high-quality assistance.
π€ Gemini-Pro Integration Powered by Google's Gemini-Pro (gemini-pro) large language model.
Capable of advanced, contextual medical conversations.
Preserves chat history during the session for a seamless experience.
π PDF Medical Report Processing Users can upload PDF medical reports (like prescriptions, diagnoses, or lab results).
The app uses PyMuPDF (fitz) to extract and read the full text content of the medical report.
Users can then ask follow-up questions specifically about the uploaded report.
π¬ Streamlit Chat Interface Clean, user-friendly chat layout using st.chat_message.
Two dedicated chat inputs:
General medical queries
Questions about uploaded medical reports
π Getting Started Prerequisites
Ensure you have the following Python libraries installed:
bash Copy Edit pip install streamlit google-generativeai pymupdf requests Run the App bash Copy Edit streamlit run app.py π API Configuration This app requires a Google API Key for Gemini-Pro. You can set this by replacing the following line in your code:
python Copy Edit GOOGLE_API_KEY = "YOUR_API_KEY_HERE" Or use an environment variable for security:
python Copy Edit import os GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY") #π§ How It Works
- Query Filtering: Uses a predefined list of common medical terms and optionally processes terms from the UMLS Metathesaurus.
Only responds to queries where at least 30% of the words are medically relevant.
- AI Chat Response: Gemini-Pro handles query responses.
Chat history is preserved within a session (st.session_state.chat_session).
- PDF Upload + Q&A: Users upload a medical report.
Text is extracted using PyMuPDF.
Users can then ask questions about the uploaded content for tailored answers.
bash Copy Edit βββ app.py # Main Streamlit app βββ README.md # Project documentation βββ requirements.txt # Python dependencies (optional) β Example Use Cases Understanding symptoms like headache, fatigue, or irregular heartbeats.
Uploading a blood test report and asking, βIs my hemoglobin level normal?β
Asking about treatments for hypertension or thyroid disorders.
Understanding medical terminology in a report.
π Security Note API keys are sensitive. Do not share them publicly.
Consider storing them using .env files and python-dotenv.
πββοΈ Future Enhancements π Authentication system
π Multilingual medical query support
π Visual summary of lab results
𧬠Genomic data-based drug recommendations
Streamlit
Google Generative AI
PyMuPDF
UMLS Metathesaurus (NIH)
π¬ Contact Author: Dia Mehak Email: diamehak96@gmail.com GitHub: @diamehak