From 1764b04ae082bf649c5819fe48bb5f04b0cbd6c9 Mon Sep 17 00:00:00 2001 From: Madhu Date: Tue, 25 Feb 2025 01:02:36 +0530 Subject: [PATCH 1/2] fixed model name to gemini-2.0-flash, used AgnoImage for the run param --- .../ai_medical_imaging.py | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/ai_agent_tutorials/ai_medical_imaging_agent/ai_medical_imaging.py b/ai_agent_tutorials/ai_medical_imaging_agent/ai_medical_imaging.py index bc86a876..b02d79e3 100644 --- a/ai_agent_tutorials/ai_medical_imaging_agent/ai_medical_imaging.py +++ b/ai_agent_tutorials/ai_medical_imaging_agent/ai_medical_imaging.py @@ -1,9 +1,10 @@ import os -from PIL import Image +from PIL import Image as PILImage from agno.agent import Agent from agno.models.google import Gemini import streamlit as st from agno.tools.duckduckgo import DuckDuckGoTools +from agno.media import Image as AgnoImage if "GOOGLE_API_KEY" not in st.session_state: st.session_state.GOOGLE_API_KEY = None @@ -42,8 +43,8 @@ medical_agent = Agent( model=Gemini( - api_key=st.session_state.GOOGLE_API_KEY, - id="gemini-2.0-flash-exp" + id="gemini-2.0-flash", + api_key=st.session_state.GOOGLE_API_KEY ), tools=[DuckDuckGoTools()], markdown=True @@ -108,11 +109,9 @@ if uploaded_file is not None: with image_container: - # Center the image using columns col1, col2, col3 = st.columns([1, 2, 1]) with col2: - image = Image.open(uploaded_file) - # Calculate aspect ratio for resizing + image = PILImage.open(uploaded_file) width, height = image.size aspect_ratio = width / height new_width = 500 @@ -133,13 +132,16 @@ with analysis_container: if analyze_button: - image_path = "temp_medical_image.png" - with open(image_path, "wb") as f: - f.write(uploaded_file.getbuffer()) - with st.spinner("🔄 Analyzing image... Please wait."): try: - response = medical_agent.run(query, images=[image_path]) + temp_path = "temp_resized_image.png" + resized_image.save(temp_path) + + # Create AgnoImage object + agno_image = AgnoImage(filepath=temp_path) # Adjust if constructor differs + + # Run analysis + response = medical_agent.run(query, images=[agno_image]) st.markdown("### 📋 Analysis Results") st.markdown("---") st.markdown(response.content) @@ -150,8 +152,5 @@ ) except Exception as e: st.error(f"Analysis error: {e}") - finally: - if os.path.exists(image_path): - os.remove(image_path) else: st.info("👆 Please upload a medical image to begin analysis") From 3affe7f9f05f39c6bef022c0d74a981f2b0ab0d0 Mon Sep 17 00:00:00 2001 From: Madhu Date: Tue, 25 Feb 2025 01:09:01 +0530 Subject: [PATCH 2/2] Readme changes --- ai_agent_tutorials/ai_medical_imaging_agent/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ai_agent_tutorials/ai_medical_imaging_agent/README.md b/ai_agent_tutorials/ai_medical_imaging_agent/README.md index e58104e8..57801ffd 100644 --- a/ai_agent_tutorials/ai_medical_imaging_agent/README.md +++ b/ai_agent_tutorials/ai_medical_imaging_agent/README.md @@ -1,6 +1,6 @@ # 🩻 Medical Imaging Diagnosis Agent -A Medical Imaging Diagnosis Agent build on agno powered by Gemini 2.0 Flash Experimental that provides AI-assisted analysis of medical images of various scans. The agent acts as a medical imaging diagnosis expert to analyze various types of medical images and videos, providing detailed diagnostic insights and explanations. +A Medical Imaging Diagnosis Agent build on agno powered by Gemini 2.0 Flash that provides AI-assisted analysis of medical images of various scans. The agent acts as a medical imaging diagnosis expert to analyze various types of medical images and videos, providing detailed diagnostic insights and explanations. ## Features @@ -57,7 +57,7 @@ A Medical Imaging Diagnosis Agent build on agno powered by Gemini 2.0 Flash Expe - Uses Gemini 2.0 Flash for analysis - Requires stable internet connection -- API usage costs apply +- Free API usage costs - 1,500 free requests per day by google! - For educational and development purposes only - Not a replacement for professional medical diagnosis