Merge pull request #183 from Madhuvod/design-agent-fix

Design Multimodal Agent: Fixed the Get() attribute error with Agno Image
This commit is contained in:
Shubham Saboo 2025-04-09 01:35:41 -05:00 committed by GitHub
commit b3c7ac7929
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,9 +1,17 @@
from agno.agent import Agent from agno.agent import Agent
from agno.models.google import Gemini from agno.models.google import Gemini
from agno.media import Image as AgnoImage
from agno.tools.duckduckgo import DuckDuckGoTools from agno.tools.duckduckgo import DuckDuckGoTools
import streamlit as st import streamlit as st
from PIL import Image
from typing import List, Optional from typing import List, Optional
import logging
from pathlib import Path
import tempfile
import os
# Configure logging for errors only
logging.basicConfig(level=logging.ERROR)
logger = logging.getLogger(__name__)
def initialize_agents(api_key: str) -> tuple[Agent, Agent, Agent]: def initialize_agents(api_key: str) -> tuple[Agent, Agent, Agent]:
try: try:
@ -54,6 +62,9 @@ def initialize_agents(api_key: str) -> tuple[Agent, Agent, Agent]:
st.error(f"Error initializing agents: {str(e)}") st.error(f"Error initializing agents: {str(e)}")
return None, None, None return None, None, None
# Set page config and UI elements
st.set_page_config(page_title="Multimodal AI Design Agent Team", layout="wide")
# Sidebar for API key input # Sidebar for API key input
with st.sidebar: with st.sidebar:
st.header("🔑 API Configuration") st.header("🔑 API Configuration")
@ -79,6 +90,7 @@ with st.sidebar:
st.markdown(""" st.markdown("""
To get your API key: To get your API key:
1. Go to [Google AI Studio](https://makersuite.google.com/app/apikey) 1. Go to [Google AI Studio](https://makersuite.google.com/app/apikey)
2. Enable the Generative Language API in your [Google Cloud Console](https://console.developers.google.com/apis/api/generativelanguage.googleapis.com)
""") """)
st.title("Multimodal AI Design Agent Team") st.title("Multimodal AI Design Agent Team")
@ -101,8 +113,7 @@ if st.session_state.api_key_input:
if design_files: if design_files:
for file in design_files: for file in design_files:
image = Image.open(file) st.image(file, caption=file.name, use_container_width=True)
st.image(image, caption=file.name, use_container_width=True)
with col2: with col2:
competitor_files = st.file_uploader( competitor_files = st.file_uploader(
@ -114,8 +125,7 @@ if st.session_state.api_key_input:
if competitor_files: if competitor_files:
for file in competitor_files: for file in competitor_files:
image = Image.open(file) st.image(file, caption=f"Competitor: {file.name}", use_container_width=True)
st.image(image, caption=f"Competitor: {file.name}", use_container_width=True)
# Analysis Configuration # Analysis Configuration
st.header("🎯 Analysis Configuration") st.header("🎯 Analysis Configuration")
@ -143,27 +153,21 @@ if st.session_state.api_key_input:
try: try:
st.header("📊 Analysis Results") st.header("📊 Analysis Results")
# Process images once
def process_images(files): def process_images(files):
processed_images = [] processed_images = []
for file in files: for file in files:
try: try:
# Create a temporary file path for the image
import tempfile
import os
temp_dir = tempfile.gettempdir() temp_dir = tempfile.gettempdir()
temp_path = os.path.join(temp_dir, f"temp_{file.name}") temp_path = os.path.join(temp_dir, f"temp_{file.name}")
# Save the uploaded file to temp location
with open(temp_path, "wb") as f: with open(temp_path, "wb") as f:
f.write(file.getvalue()) f.write(file.getvalue())
# Add the path to processed images agno_image = AgnoImage(filepath=Path(temp_path))
processed_images.append(temp_path) processed_images.append(agno_image)
except Exception as e: except Exception as e:
st.error(f"Error processing image {file.name}: {str(e)}") logger.error(f"Error processing image {file.name}: {str(e)}")
continue continue
return processed_images return processed_images
@ -233,20 +237,10 @@ if st.session_state.api_key_input:
st.subheader("📊 Market Analysis") st.subheader("📊 Market Analysis")
st.markdown(response.content) st.markdown(response.content)
# Combined Insights
if len(analysis_types) > 1:
st.subheader("🎯 Key Takeaways")
st.info("""
Above you'll find detailed analysis from multiple specialized AI agents, each focusing on their area of expertise:
- Visual Design Agent: Analyzes design elements and patterns
- UX Agent: Evaluates user experience and interactions
- Market Research Agent: Provides market context and opportunities
""")
except Exception as e: except Exception as e:
st.error(f"An error occurred during analysis: {str(e)}") logger.error(f"Error during analysis: {str(e)}")
st.error("Please check your API key and try again.") st.error("An error occurred during analysis. Please check the logs for details.")
else: else:
st.warning("Please upload at least one design to analyze.") st.warning("Please upload at least one design to analyze.")
else: else: