Configure Gradio SDK demo.launch with all FastAPI routes for ZeroGPU
Browse files- Dockerfile +0 -46
- README.md +2 -2
- app.py +10 -8
Dockerfile
DELETED
|
@@ -1,46 +0,0 @@
|
|
| 1 |
-
# ==============================================================================
|
| 2 |
-
# CropAI Hugging Face Spaces Production Dockerfile
|
| 3 |
-
# Optimized for Hugging Face Spaces Free Tier (2 vCPU, 16 GB RAM, Port 7860)
|
| 4 |
-
# User UID 1000 required by Hugging Face Spaces security sandbox
|
| 5 |
-
# ==============================================================================
|
| 6 |
-
|
| 7 |
-
FROM python:3.11-slim
|
| 8 |
-
|
| 9 |
-
# Create Hugging Face default non-root user (UID 1000)
|
| 10 |
-
RUN useradd -m -u 1000 user
|
| 11 |
-
WORKDIR /app
|
| 12 |
-
|
| 13 |
-
ENV PYTHONUNBUFFERED=1 \
|
| 14 |
-
PYTHONDONTWRITEBYTECODE=1 \
|
| 15 |
-
PORT=7860 \
|
| 16 |
-
HOST=0.0.0.0 \
|
| 17 |
-
APP_ENV=production
|
| 18 |
-
|
| 19 |
-
# Install OS libraries for Pillow and native builds
|
| 20 |
-
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 21 |
-
build-essential \
|
| 22 |
-
libjpeg-dev \
|
| 23 |
-
zlib1g-dev \
|
| 24 |
-
curl \
|
| 25 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 26 |
-
|
| 27 |
-
# Install Python packages
|
| 28 |
-
COPY backend/requirements.txt /app/requirements.txt
|
| 29 |
-
RUN pip install --no-cache-dir --upgrade pip && \
|
| 30 |
-
pip install --no-cache-dir -r /app/requirements.txt
|
| 31 |
-
|
| 32 |
-
# Copy entire backend source code
|
| 33 |
-
COPY backend /app/backend
|
| 34 |
-
|
| 35 |
-
# Grant ownership to non-root user
|
| 36 |
-
RUN chown -R user:user /app
|
| 37 |
-
USER user
|
| 38 |
-
|
| 39 |
-
EXPOSE 7860
|
| 40 |
-
|
| 41 |
-
# Healthcheck
|
| 42 |
-
HEALTHCHECK --interval=30s --timeout=10s --start-period=15s --retries=3 \
|
| 43 |
-
CMD curl -f http://localhost:7860/health || exit 1
|
| 44 |
-
|
| 45 |
-
# Start FastAPI application on Port 7860
|
| 46 |
-
CMD ["uvicorn", "backend.main:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
README.md
CHANGED
|
@@ -3,8 +3,8 @@ title: CropAI
|
|
| 3 |
emoji: 🌾
|
| 4 |
colorFrom: green
|
| 5 |
colorTo: green
|
| 6 |
-
sdk:
|
| 7 |
-
|
| 8 |
pinned: false
|
| 9 |
license: mit
|
| 10 |
short_description: CropAI Enterprise Agronomic Backend API
|
|
|
|
| 3 |
emoji: 🌾
|
| 4 |
colorFrom: green
|
| 5 |
colorTo: green
|
| 6 |
+
sdk: gradio
|
| 7 |
+
app_file: app.py
|
| 8 |
pinned: false
|
| 9 |
license: mit
|
| 10 |
short_description: CropAI Enterprise Agronomic Backend API
|
app.py
CHANGED
|
@@ -1,20 +1,19 @@
|
|
| 1 |
# -*- coding: utf-8 -*-
|
| 2 |
"""
|
| 3 |
-
CropAI Hugging Face Spaces Entry Point
|
| 4 |
Mounts CropAI Enterprise FastAPI Server inside Hugging Face Gradio Space.
|
| 5 |
Provides:
|
| 6 |
-
1. Public interactive Web Landing Page
|
| 7 |
2. Interactive Swagger REST API documentation at '/docs'
|
| 8 |
-
3. 30 Production REST Endpoints for CropAI Flutter Mobile App at '/api/v1/...'
|
| 9 |
"""
|
| 10 |
|
| 11 |
import sys
|
| 12 |
from pathlib import Path
|
| 13 |
sys.path.insert(0, str(Path(__file__).parent))
|
| 14 |
|
| 15 |
-
import uvicorn
|
| 16 |
import gradio as gr
|
| 17 |
-
from backend.main import app as
|
| 18 |
|
| 19 |
# Web Landing Page for visitors opening the Space in browser
|
| 20 |
with gr.Blocks(title="🌾 CropAI Agronomic Cloud") as demo:
|
|
@@ -50,8 +49,11 @@ with gr.Blocks(title="🌾 CropAI Agronomic Cloud") as demo:
|
|
| 50 |
* **Drone VRA:** Autonomous Spot-Spraying Lawnmower Grid Generator
|
| 51 |
""")
|
| 52 |
|
| 53 |
-
#
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
if __name__ == "__main__":
|
| 57 |
-
|
|
|
|
| 1 |
# -*- coding: utf-8 -*-
|
| 2 |
"""
|
| 3 |
+
CropAI Hugging Face Spaces Entry Point (Gradio + FastAPI ZeroGPU Compatible)
|
| 4 |
Mounts CropAI Enterprise FastAPI Server inside Hugging Face Gradio Space.
|
| 5 |
Provides:
|
| 6 |
+
1. Public interactive Web Landing Page
|
| 7 |
2. Interactive Swagger REST API documentation at '/docs'
|
| 8 |
+
3. All 30 Production REST Endpoints for CropAI Flutter Mobile App at '/api/v1/...'
|
| 9 |
"""
|
| 10 |
|
| 11 |
import sys
|
| 12 |
from pathlib import Path
|
| 13 |
sys.path.insert(0, str(Path(__file__).parent))
|
| 14 |
|
|
|
|
| 15 |
import gradio as gr
|
| 16 |
+
from backend.main import app as backend_app
|
| 17 |
|
| 18 |
# Web Landing Page for visitors opening the Space in browser
|
| 19 |
with gr.Blocks(title="🌾 CropAI Agronomic Cloud") as demo:
|
|
|
|
| 49 |
* **Drone VRA:** Autonomous Spot-Spraying Lawnmower Grid Generator
|
| 50 |
""")
|
| 51 |
|
| 52 |
+
# Attach all FastAPI backend routes onto Gradio's internal FastAPI app
|
| 53 |
+
existing_paths = {getattr(r, 'path', '') for r in demo.app.routes}
|
| 54 |
+
for route in backend_app.routes:
|
| 55 |
+
if getattr(route, 'path', '') not in existing_paths:
|
| 56 |
+
demo.app.routes.append(route)
|
| 57 |
|
| 58 |
if __name__ == "__main__":
|
| 59 |
+
demo.launch()
|