Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Processing Images with CrewAI,GPT4 #531

Open
WAILMAGHRANE opened this issue Apr 29, 2024 · 2 comments
Open

Processing Images with CrewAI,GPT4 #531

WAILMAGHRANE opened this issue Apr 29, 2024 · 2 comments

Comments

@WAILMAGHRANE
Copy link

Can CrewAI's agents process images and provide results based on them? I know that CrewAI uses GPT-4 Turbo, which can handle both text and images, but I'm not sure how to pass an image to the agent and get a result.

@Rahul-Kashyap2
Copy link

@WAILMAGHRANE Same Question

@WAILMAGHRANE
Copy link
Author

I've used this function, and it worked well. (I'm using Gemini.)

class Vision:
@tool("Doc Verification")
def vision(prompt: str, path: str):
"""
C'est un outil utilisé pour analyser les images en fonction d'une instruction à l'aide de Gemini.

    Paramètres :
    - prompt (str) : L'instruction textuelle pour l'analyse de l'image.
    - path (str) : Le chemin complet vers le fichier image.

    Renvoie :
    - str : Le texte de réponse généré par le modèle de vision Gemini.
    """

    # Vérifier la disponibilité de la clé API (à remplacer par votre gestion des erreurs)
    if not GOOGLE_API_KEY:
        raise ValueError("Clé API Gemini non fournie.")

    try:
        # Ouvrir l'image
        image = Image.open(path)

        # Créer une instance de modèle génératif (en supposant que 'genai' est la bibliothèque)
        model = genai.GenerativeModel(model_name="gemini-pro-vision")

        # Générer du contenu en utilisant l'instruction et l'image
        response = model.generate_content([prompt, image])

        return response.text

    except FileNotFoundError:
        return "Erreur : Fichier image introuvable."
    except Exception as e:  # Attraper d'autres erreurs potentielles
        return f"Erreur : {e}"

@WAILMAGHRANE Same Question

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants