Spaces:
Paused
Paused
kgupta21 commited on
Commit ·
5b7e38a
1
Parent(s): ecd47e6
Add enhanced radiology teaching application with logging and version tracking
Browse files4 unmodified lines5678910111213144 unmodified lines19202122232424 unmodified lines4950515253545556575859606162636465664 unmodified lines7172737475767740 unmodified lines1181191201214 unmodified linesfrom PIL import Imageimport ioimport base64# Load only 10 rows from the datasetdataset = load_dataset("itsanmolgupta/mimic-cxr-dataset", split="train").select(range(10))df = pd.DataFrame(dataset)def encode_image_to_base64(image_bytes):return base64.b64encode(image_bytes).decode('utf-8')4 unmodified linestry:client = OpenAI(api_key=api_key, base_url="https://api.deepseek.com")prompt = f"""You are an expert radiologist reviewing a trainee's chest X-ray report.24 unmodified linesreturn response.choices[0].message.contentexcept Exception as e:return f"Error analyzing report: {str(e)}"def load_random_case(hide_ground_truth):# Randomly select a case from our datasetrandom_case = df.sample(n=1).iloc[0]# Get the image, findings, and impressionimage = random_case['image']findings = "" if hide_ground_truth else random_case['findings']impression = "" if hide_ground_truth else random_case['impression']return image, findings, impressiondef process_case(image, user_findings, hide_ground_truth, api_key, current_findings="", current_impression=""):if hide_ground_truth:4 unmodified lines# Create the Gradio interfacewith gr.Blocks() as demo:gr.Markdown("# Radiology Report Training System")gr.Markdown("### Practice your chest X-ray reading and reporting skills")with gr.Row():40 unmodified linesoutputs=[ground_truth_findings, ground_truth_impression, analysis_output])demo.launch()4 unmodified lines5678910111213141516171819202122232425262728294 unmodified lines3435363738394024 unmodified lines6566676869707172737475767778798081828384858687884 unmodified lines9394959697989940 unmodified lines1401411421431444 unmodified linesfrom PIL import Imageimport ioimport base64import logging# Set up logginglogging.basicConfig(level=logging.INFO)logger = logging.getLogger(__name__)# App versionAPP_VERSION = "1.0.0"logger.info(f"Starting Radiology Teaching App v{APP_VERSION}")try:# Load only 10 rows from the datasetlogger.info("Loading MIMIC-CXR dataset...")dataset = load_dataset("itsanmolgupta/mimic-cxr-dataset", split="train").select(range(10))df = pd.DataFrame(dataset)logger.info(f"Successfully loaded {len(df)} cases")except Exception as e:logger.error(f"Error loading dataset: {str(e)}")raisedef encode_image_to_base64(image_bytes):return base64.b64encode(image_bytes).decode('utf-8')4 unmodified linestry:client = OpenAI(api_key=api_key, base_url="https://api.deepseek.com")logger.info("Analyzing report with DeepSeek...")prompt = f"""You are an expert radiologist reviewing a trainee's chest X-ray report.24 unmodified linesreturn response.choices[0].message.contentexcept Exception as e:logger.error(f"Error in report analysis: {str(e)}")return f"Error analyzing report: {str(e)}"def load_random_case(hide_ground_truth):try:# Randomly select a case from our datasetrandom_case = df.sample(n=1).iloc[0]logger.info("Loading random case...")# Get the image, findings, and impressionimage = random_case['image']findings = "" if hide_ground_truth else random_case['findings']impression = "" if hide_ground_truth else random_case['impression']return image, findings, impressionexcept Exception as e:logger.error(f"Error loading random case: {str(e)}")return None, "Error loading case", "Error loading case"def process_case(image, user_findings, hide_ground_truth, api_key, current_findings="", current_impression=""):if hide_ground_truth:4 unmodified lines# Create the Gradio interfacewith gr.Blocks() as demo:gr.Markdown(f"# Radiology Report Training System v{APP_VERSION}")gr.Markdown("### Practice your chest X-ray reading and reporting skills")with gr.Row():40 unmodified linesoutputs=[ground_truth_findings, ground_truth_impression, analysis_output])logger.info("Starting Gradio interface...")demo.launch()
app.py+36-13