Spaces:
Configuration error
Configuration error
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)
|