CropAI / app.py
bapi143's picture
Deploy CropAI Deep Learning backend, YOLO11 pest model and Audio-CNN
0ee27f7
Raw History Blame Contribute Delete
3.07 kB
# -*- 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"
}
)