# -*- coding: utf-8 -*- """ CropAI Hugging Face Spaces Entry Point (Gradio + FastAPI ZeroGPU Compatible) Mounts CropAI Enterprise FastAPI Server inside Hugging Face Gradio Space. Provides: 1. Public interactive Web Landing Page 2. Interactive Swagger REST API documentation at '/docs' 3. All 30 Production REST Endpoints for CropAI Flutter Mobile App at '/api/v1/...' """ import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).parent)) import gradio as gr from backend.main import app as backend_app # ZeroGPU Startup Detection Handler try: import spaces @spaces.GPU def zero_gpu_pipeline(x: str = "") -> str: """Keeps Hugging Face ZeroGPU environment verified and active.""" return f"CropAI ZeroGPU Pipeline Active: {x}" except Exception: def zero_gpu_pipeline(x: str = "") -> str: return f"CropAI CPU Pipeline Active: {x}" # Web Landing Page for visitors opening the Space in browser with gr.Blocks(title="🌾 CropAI Agronomic Cloud") as demo: gr.Markdown("# 🌾 CropAI: Autonomous Plant Pathology & Advisory Ecosystem") gr.Markdown(""" ### πŸš€ Cloud Inference Backend is Active & Running 24/7! This Hugging Face Space hosts the production cloud inference backend for the **CropAI Mobile Application**. --- ### πŸ“± Mobile App Connection Settings: In your Flutter app (`frontend/lib/config/app_config.dart`), set: ```dart static const String productionCloudUrl = "https://bapi143-cropai.hf.space"; static String baseUrl = productionCloudUrl; ``` --- ### πŸ”— Quick Links: * πŸ“– **[Interactive Swagger API Docs](/docs)** β€” Test all 30 REST endpoints directly in browser * 🩺 **[Backend Health Check](/health)** β€” Verify active AI model and system status * 🌾 **[Detectable Crops Catalog](/api/v1/crops)** β€” View 127+ supported pathologies * πŸ“Š **[Dataset Platforms Catalog](/api/v1/datasets/platforms)** β€” 338,000+ benchmark image samples --- ### 🧠 Active AI & Multi-Engine Suite: * **Multimodal Vision:** Google Gemini 3.8 Flash (Cascading Failover) * **Leaf Spectroscopy:** Early Chlorophyll Breakdown & Botanical Gatekeeper * **Bio-Acoustics AI:** Deep Learning Audio-CNN & Log Mel-Spectrogram Stem Pest Eavesdropper * **Pest Detection Engine:** AgroAI YOLO11 Small (IP102 Benchmark Deep Learning) * **Bio-Twinβ„’:** Thermodynamic Dew-Point & Spore Germination Index (SGI) * **Thermal Shock AI:** Nocturnal Radiation Frost ($T \\le 2^\\circ\\text{C}$) & Terminal Heatwave Defense * **Solar IoT Hub:** LoRaWAN Telemetry Ingestion, Dual-Depth Soil VWC, PWP Drought Alarms * **Drone VRA:** Autonomous Spot-Spraying Lawnmower Grid Generator """) if __name__ == "__main__": demo.launch( ssr_mode=False, app_kwargs={ "routes": list(backend_app.routes), "docs_url": "/docs", "redoc_url": "/redoc", "title": "CropAI Agricultural Cloud API", "version": "1.2.0" } )