import gradio as gr import torch from PIL import Image from transformers import pipeline # 1. Initialize specialized Hugging Face pipelines # Using BLIP for structural backdrop captioning (Skyscrapers, Promenades, etc.) captioner = pipeline("image-text-to-text", model="Salesforce/blip-image-captioning-base") # Using ViT fine-tuned on iNaturalist for fine-grained vegetation/flora recognition plant_classifier = pipeline("image-classification", model="microsoft/swin-tiny-patch4-window7-224") def process_park_landscape(input_image): if input_image is None: return None, "No image uploaded.", "No image uploaded." # --- Model 1: Custom YOLOv8 (Placeholder for your amenities/palms weights) --- # In practice: # model = ultralytics.YOLO("your_fine_tuned_weights.pt") # results = model(input_image) # annotated_img = results[0].plot() annotated_img = input_image # Placeholder fallback # --- Model 2: Structural & Backdrop Captioning --- try: caption_output = captioner(input_image) scene_description = caption_output[0]['generated_text'] except Exception as e: scene_description = f"Error generating scene analysis: {str(e)}" # --- Model 3: Fine-Grained Species/Flora Identification --- try: classifications = plant_classifier(input_image) # Format top 3 predictions cleanly for gr.Label species_predictions = {pred['label']: pred['score'] for pred in classifications[:3]} except Exception as e: species_predictions = {"Error classifying vegetation": 1.0} return annotated_img, species_predictions, scene_description # --- Gradio UI Custom Styling --- css = """ .gradio-container { background-color: #fcfbfa; font-family: sans-serif; } .feedback-header { color: #2e4a36; font-weight: 600; } button.primary-btn { background-color: #3b5944 !important; color: white !important; } """ with gr.Blocks(css=css) as demo: gr.Markdown("
An interdisciplinary computer vision platform analyzing " "the visual ecology, amenities, and urban-nature interfaces of Abu Dhabi's park network.
" ) gr.HTML("