Spaces:
Sleeping
Sleeping
Download my_env/models.py from SheSync/meta-hackathon-project: direct link, hf CLI and curl.
- Browser
- Download file 3.88 kB
-
https://huggingface.co/spaces/SheSync/meta-hackathon-project/resolve/main/my_env/models.py
- Command line
-
hf download hf://spaces/SheSync/meta-hackathon-project/my_env/models.py
-
curl -L -o models.py https://huggingface.co/spaces/SheSync/meta-hackathon-project/resolve/main/my_env/models.py
3.88 kB
| # Copyright (c) Meta Platforms, Inc. and affiliates. | |
| # All rights reserved. | |
| # | |
| # This source code is licensed under the BSD-style license found in the | |
| # LICENSE file in the root directory of this source tree. | |
| """ | |
| Data models for the Smart Farm Irrigation Environment. | |
| This environment simulates a real-world crop irrigation management task | |
| where an AI agent decides how much to water crops based on: | |
| - Weather conditions (temperature, rainfall) from Weather API | |
| - Soil moisture (from sensor if available, else calculated) | |
| - Crop health (selected by user) | |
| - Crop stage and day number (auto-managed by code) | |
| """ | |
| from enum import Enum | |
| from typing import Optional | |
| from openenv.core.env_server.types import Action, Observation | |
| from pydantic import Field | |
| class CropHealthStatus(str, Enum): | |
| """ | |
| User selects current crop health. | |
| Like a dropdown β only these 4 options allowed. | |
| """ | |
| POOR="poor" | |
| FAIR="fair" | |
| GOOD="good" | |
| EXCELLENT="excellent" | |
| class WaterAmount(str, Enum): | |
| """ | |
| AI selects how much to water the crop. | |
| This is the ACTION the AI takes every day. | |
| """ | |
| NONE="none" | |
| LOW="low" | |
| MEDIUM="medium" | |
| HIGH="high" | |
| class CropStage(str, Enum): | |
| """ | |
| Crop growth stage β automatically set by code based on day number. | |
| User never touches this. Code manages it. | |
| Day 1-10 β Seedling | |
| Day 11-20 β Growing | |
| Day 21-30 β Mature | |
| """ | |
| SEEDLING = "seedling" | |
| GROWING="growing" | |
| MATURE="mature" | |
| class FarmObservation(Observation): | |
| """ | |
| Everything the AI can observe about the farm at any given moment. | |
| Sources: | |
| - temperature, rainfall β fetched from Weather API | |
| - soil_moisture β from sensor (optional) or calculated | |
| - crop_health β selected by user (dropdown) | |
| - day_number, crop_stage β auto-managed by code | |
| """ | |
| #FROM WEATHER API | |
| temperature: float = Field( | |
| ..., | |
| description="Current temperature in Celsius (from Weather API)", | |
| ge=0.0, #min | |
| le=60.0 #max | |
| ) | |
| rainfall: float = Field( | |
| ..., | |
| description="Rainfall today in mm (from Weather API)", | |
| ge=0.0, #min | |
| le=500.0 #max | |
| ) | |
| #FROM SENSOR OR CALCULATED | |
| soil_moisture: Optional[float] = Field( | |
| default=None, | |
| description=( | |
| "Soil moisture percentage (0-100). " | |
| "Provide this if you have a sensor. " | |
| "If None, code will calculate it automatically " | |
| "based on rainfall and temperature." | |
| ), | |
| ge=0.0, | |
| le=100.0 | |
| ) | |
| #USER SELECTS | |
| crop_health: CropHealthStatus = Field( | |
| ..., | |
| description="Current crop health selected by user (poor/fair/good/excellent)" | |
| ) | |
| #AUTO MANAGED BY CODE | |
| day_number: int = Field( | |
| default=1, | |
| description="Current day of simulation (1-30). Auto-incremented by code.", | |
| ge=1, | |
| le=30 | |
| ) | |
| crop_stage: CropStage = Field( | |
| default=CropStage.SEEDLING, | |
| description="Current crop growth stage. Auto-set by code based on day_number." | |
| ) | |
| class FarmAction(Action): | |
| """ | |
| The only decision the AI makes every day: | |
| How much water should I give the crop today? | |
| """ | |
| water_amount: WaterAmount = Field( | |
| ..., | |
| description=( | |
| "How much to water the crop today. " | |
| "none=0mm, low=10mm, medium=25mm, high=50mm" | |
| ) | |
| ) | |
| class FarmReward: | |
| """ | |
| Score given to AI after each action. | |
| Tells the AI how well it did. | |
| """ | |
| value: float = Field( | |
| ..., | |
| description="Reward score between 0.0 (worst) and 1.0 (best)", | |
| ge=-1.0, # can go negative for very bad actions | |
| le=1.0 | |
| ) | |
| reason: str = Field( | |
| ..., | |
| description="Human-readable explanation of why this score was given" | |
| ) | |