import streamlit as st import os import base64 from langchain_google_genai import ChatGoogleGenerativeAI from langchain_core.messages import HumanMessage from dotenv import load_dotenv # Load API key from .env file load_dotenv() GEMINI_API_KEY = os.getenv("GEMINI_API_KEY") # Initialize the Gemini model llm = ChatGoogleGenerativeAI( model="gemini-2.0-flash", max_tokens=4000, api_key=GEMINI_API_KEY ) def encode_file(file): return base64.b64encode(file.read()).decode() def summarize_report(file, file_type): encoded_string = encode_file(file) prompt = """You are a highly advanced medical document analysis AI designed to assist live agents and doctors by extracting and summarizing fluctuating or improper test results from uploaded medical reports. Your task is to carefully parse the document, identify irregularities in test values, highlight trends that indicate instability, and generate a clear, structured summary. Ensure the summary includes: 1) The test names with significant fluctuations or abnormal values. 2) A brief comparison of fluctuating values over time (if historical data is available). 3) Possible concerns based on deviations from normal ranges. 4) A concise, professional summary that can be quickly reviewed by a medical expert or triage bot for primary screening. Format the output to be clear, concise, and medically relevant. Do not make any medical diagnosesโonly summarize fluctuations and abnormalities in an easily interpretable manner.""" content = [{"type": "text", "text": prompt}] if file_type in ["image/jpeg", "image/png", "image/webp"]: content.append({"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{encoded_string}"}}) else: content.append({"type": "text", "text": encoded_string}) message = HumanMessage(content=content) ai_msg = llm.invoke([message]) return ai_msg.content # Streamlit UI st.set_page_config(page_title="Medical Report Summarizer", layout="wide", page_icon="๐") # Custom CSS for styling st.markdown(""" """, unsafe_allow_html=True) # Header Section st.title("๐ Call on Doc Medical Report Summarizer") st.markdown("""