Journey to llm

La Classification de photos en mode strictement local devient réalité !

Grâce au modèle Llava et à quelques lignes de code Python, j’ai traité ces photos en quelques minutes, sans aucune dépendance de ressources externes…

Retrouvons notre souveraineté, vers une gestion de nos données en toute confidentialité.


Source

  1. Number of clearly identifiable people: 1
  2. Number and type of clearly identifiable animals: 0
  3. Indoors or outdoors: Outdoors
  4. Number of clearly identifiable objects: 1 (sign)
  5. Keywords for search purposes: astronaut, sign, mars, costume, science fiction
  6. Description: This image shows an individual dressed in a full-body white spacesuit and helmet, standing on the side of a road. The person is holding a cardboard sign with the word “MARS” written in black capital letters. The individual’s attire suggests they are portraying a space traveler or astronaut, which is typically associated with Mars exploration. The setting appears to be a rural or semi-rural area, as there are fields and grass in the background, along with a clear sky. The overall mood of the image seems lighthearted and humorous, likely intended for amusement rather than depicting a serious astronomy or space exploration context.

Source

  1. The image features one person, a child who is holding a teddy bear.
  2. There are no animals visible in the photograph.
  3. The setting appears to be outdoors, possibly in an urban environment given the presence of a bench and the sidewalk.
  4. The objects include the teddy bear held by the child, which is a toy.
  5. Keywords for search purposes could be “child,” “teddy bear,” “outdoor setting,” “street scene,” and “toy.”
  6. Description: A young child in an outdoor setting, holding a teddy bear, seems to be posing for the photo with one hand on their face and the other arm around the stuffed animal. The child is dressed casually and appears to be standing next to a bench. The overall mood of the image seems calm and nostalgic, capturing a moment of childhood innocence.

Source

  1. There is one person clearly identifiable in the photograph.
  2. There are no animals visible in the image.
  3. The setting appears to be indoors, specifically inside a boat or ferry cabin, as indicated by the benches and ceiling structure.
  4. There are several objects visible in the image, including benches, a person sitting on one of them, and possibly some other items that are not distinctly identifiable.
  5. Keywords: Boat, Ferry, Cabin, Seating, Person.
  6. Description: The photograph captures an interior scene within a boat or ferry cabin. A person is seated alone on one of the benches, which seem to be made of wood with metal frames. The cabin has white walls and a metal roof with a large skylight at the top. The person appears to be resting or waiting. There is no text visible in the image.

Source

  1. There is one person identifiable in the image.
  2. No animals are visible in this photograph.
  3. The setting appears to be indoors, with a kitchen counter visible.
  4. Numerous objects can be identified: a plate of food, strawberries, a knife, a bowl, and what looks like a cake.
  5. Keywords for search purposes could include “cooking”, “kitchen”, “dessert”, “preparation”, and “food”.
  6. Description: The image captures a moment in the kitchen where someone is in the process of preparing food, possibly a dessert or pastry, as suggested by the presence of strawberries and what appears to be a cake on the counter. The person seems to be handling the ingredients carefully, indicating attention to detail and care for presentation. The kitchen counter is neatly organized with tools of the trade such as a knife and a bowl, implying an efficient cooking environment. The image conveys a sense of domestic warmth and culinary craftsmanship.

Source

  1. There is one clearly identifiable person in the photograph.
  2. No animals are clearly identifiable in this image.
  3. The setting appears to be indoors, as suggested by the presence of a chair and a couch.
  4. There are several objects in the room that can be identified, including a dog, a cell phone, a chair, a couch, and a potted plant.
  5. Keywords: Man, Dog, Cell Phone, Indoor, Chair, Couch.
  6. The man is sitting on the floor with his dog by his side. He has a beard and appears to be using his cell phone. Behind him, there’s a cozy living room scene with a couch in the background and a potted plant nearby. The ambiance of the image suggests a quiet, comfortable home setting.

Source

  1. There are three clearly identifiable people in the photograph.
  2. There is no animal visible in the image.
  3. The setting appears to be outdoors, possibly a public space like a park or near a building.
  4. There are several objects present: a person is holding a smartphone, there’s a laptop computer, and what seems to be a cup on a surface nearby.
  5. Keywords: People, Smartphone, Laptop, Public space.
  6. Description: The image shows three individuals engaged in conversation while seated at an outdoor setting. One person is holding a smartphone and appears to be looking at it. They are all casually dressed, suggesting a relaxed environment. A laptop is open nearby, which could indicate work or study taking place. The surrounding architecture features modern design elements such as metal fencing and stone steps, which complement the casual atmosphere of the group’s gathering.

Source

  1. Three elephants are clearly identifiable in the photograph.
  2. There are no animals other than elephants in this image.
  3. The setting appears to be outdoors, as indicated by the natural surroundings and the presence of water.
  4. There is a small pond with some vegetation on the edge, which suggests this might be a wildlife reserve or park.
  5. Keywords: Elephant, Wildlife, Nature, Safari, Family.
  6. Description: The photograph depicts a family of elephants gathered by a body of water, possibly for drinking. They are standing near each other and appear to be in close proximity. This setting is likely within a wildlife reserve or park where such encounters with wildlife can occur.

  1. Number of clearly identifiable people: 1
  2. Number and type of clearly identifiable animals: 0
  3. Indoors or outdoors: Indoors
  4. Number of clearly identifiable objects: 1 (sun)
  5. Keywords for search purposes: Penguin, costume, sunglasses, tuxedo, puffin
  6. Description: The image features an anthropomorphic penguin character wearing a tuxedo and sunglasses. It is set against a background that suggests an indoor setting with warm lighting. The penguin appears to be standing in front of a sun or light source, which creates a circular glow effect around its head. The overall vibe of the image is whimsical and styled, giving it a stylized, illustrated quality rather than a realistic one.

Source

  1. Number of clearly identifiable people: Zero
  2. Number and type of clearly identifiable animals: One deer, likely a stag, with antlers and a white coat in the wilderness
  3. Indoors or outdoors: Outdoors
  4. Number of clearly identifiable objects: Two - the tree and the deer
  5. Keywords for search purposes: Deer, antler, forest, nature, wilderness
  6. Description: The image captures a serene moment in a forest or wilderness area. A majestic stag stands tall under an old tree with bare branches, suggesting that it is either autumn or winter. The deer’s white coat contrasts beautifully with the lush greenery around it. The calm and peaceful atmosphere of the scene is both tranquil and captivating.

Script :

#!/bin/env python3

import requests
import base64
import os
from pathlib import Path

OLLAMA_URL = 'http://192.168.1.189:11434/api/generate'
PROMPT = """
Describe the main aspects of this photograph using this format:

1. Number of clearly identifiable people. Can be zero or more.
2. Number and type of clearly identifiable animals. Can be zero or more.
3. Indoors or outdoors.
4. Number of clearly identifiable objects. Can be zero or more.
5. List of up to five keywords for search purposes.
6. Give a description with the heading "Description".
"""

def generate_image_description(input_file, prompt):
    with open(input_file, 'rb') as image_file:
        encoded_image = base64.b64encode(image_file.read()).decode('utf-8')
    
    payload = {
        "model": "llava",
        "prompt": prompt,
        "images": [encoded_image],
        "stream": False,
        "temperature": 0,
        "seed": 10,
    }
    
    response = requests.post(OLLAMA_URL, json=payload)
    response.raise_for_status()
    
    return response.json()["response"]


def process_jpg_file(file_path):
    """
    Process each .jpg file in provided directory.
    :param file_path: Path of the .jpg file
    """
    print(f"Processing {file_path}")
    
    text_file = str(Path(file_path).with_suffix(".txt"))
    if os.path.exists(text_file):
        print(f"Skipping {file_path}")
        return

    image_description = generate_image_description(file_path, PROMPT)
    print(image_description)
    print(f"Writing description to {text_file}")
    with open(text_file, "w") as f:
        f.write(image_description)


def find_and_process_jpg_files(start_dir):
    """
    Recursively finds all images
    :param start_dir: Directory to start the search from
    """
    for root, dirs, files in os.walk(start_dir):
        for file in files:
            if (file.lower().endswith('.jpg') or file.lower().endswith('.jpeg')):
                file_path = os.path.join(root, file)
                process_jpg_file(file_path)

def main():
    find_and_process_jpg_files('.')


if __name__ == "__main__":
    main()
Eric
Eric
🛡️ Cybersecurity enthusiast driven by curiosity and the desire to share.