File size: 1,441 Bytes
b106165
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

# Install:
# pip install transformers torch pillow duckduckgo-search

from transformers import pipeline
from PIL import Image
from duckduckgo_search import DDGS

print("😊 Starting FaceMatch AI...")

# AI that describes images
vision_ai = pipeline(
    "image-to-text",
    model="Salesforce/blip-image-captioning-base"
)

def search_face_image(photo_path):
    print("\n😊 Hey! Let's look at your image.")

    try:
        image = Image.open(photo_path).convert("RGB")

        print("πŸ”Ž Analyzing the image...")
        description = vision_ai(image)[0]["generated_text"]

        print(f"🧠 Image details: {description}")
        print("🌐 Searching for related public webpages...")

        with DDGS() as search:
            results = list(search.text(
                description,
                max_results=10
            ))

        if results:
            print("\n😊 Yay! I found some relevant search results!")

            for i, result in enumerate(results, 1):
                print(f"\nπŸ“„ Result {i}: {result['title']}")
                print(f"πŸ”— Link: {result['href']}")
                print(f"πŸ“ {result['body']}")
        else:
            print("πŸ™‚ No results this time. Let's try another image.")

    except Exception as error:
        print(f"πŸ˜• Something went wrong: {error}")

if __name__ == "__main__":
    photo = input("πŸ“· Enter the path to your image: ")
    search_face_image(photo)