Juliet / app.py
FernFox's picture
Create app.py
b106165 verified
Raw History Blame Contribute Delete
1.44 kB
# 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)