Spaces:
Sleeping
Sleeping
suhaas-code commited on
Commit ·
f63f438
1
Parent(s): ddf8803
updated defaults
Browse files- README.md +154 -4
- final-requirements.md +0 -55
- inference.py +5 -5
- openenv.yaml +7 -0
README.md
CHANGED
|
@@ -1,10 +1,160 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
colorTo: blue
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: FarmRL OpenEnv Submission
|
| 3 |
+
emoji: 🌾
|
| 4 |
+
colorFrom: green
|
| 5 |
colorTo: blue
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
---
|
| 9 |
|
| 10 |
+
# FarmRL OpenEnv Submission
|
| 11 |
+
|
| 12 |
+
A reinforcement learning environment and agent for optimizing farm management decisions using the OpenEnv framework.
|
| 13 |
+
|
| 14 |
+
## Overview
|
| 15 |
+
|
| 16 |
+
FarmRL trains an intelligent agent to manage crop farming decisions by controlling irrigation, fertilizer application, and pesticide use. The agent learns from a real agricultural dataset and aims to maximize crop yield while maintaining sustainability.
|
| 17 |
+
|
| 18 |
+
**Key Features:**
|
| 19 |
+
- OpenEnv-compliant REST API for environment interaction
|
| 20 |
+
- LLM-based inference via OpenAI-compatible endpoints
|
| 21 |
+
- Tabular RL training with preprocessing pipeline
|
| 22 |
+
- Grading and evaluation framework
|
| 23 |
+
|
| 24 |
+
## Quick Start
|
| 25 |
+
|
| 26 |
+
### Prerequisites
|
| 27 |
+
- Python 3.11+
|
| 28 |
+
- `uv` package manager (recommended) or pip
|
| 29 |
+
- Environment variables configured (see Configuration section)
|
| 30 |
+
|
| 31 |
+
### Installation
|
| 32 |
+
|
| 33 |
+
```bash
|
| 34 |
+
uv pip install -e .
|
| 35 |
+
```
|
| 36 |
+
|
| 37 |
+
Or with pip:
|
| 38 |
+
```bash
|
| 39 |
+
pip install -r requirements.txt
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
### Configuration
|
| 43 |
+
|
| 44 |
+
Create a `.env` file in the project root with required credentials:
|
| 45 |
+
|
| 46 |
+
```env
|
| 47 |
+
# API Configuration (defaults provided for base URL and model)
|
| 48 |
+
API_BASE_URL=https://api.openai.com/v1
|
| 49 |
+
MODEL_NAME=gpt-4o-mini
|
| 50 |
+
TASK_NAME=farm-yield-optimization
|
| 51 |
+
BENCHMARK=farmrl
|
| 52 |
+
PORT=7860
|
| 53 |
+
|
| 54 |
+
# Required API Credentials (no defaults)
|
| 55 |
+
OPENAI_API_KEY=your_api_key_here
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
**Environment Variables:**
|
| 59 |
+
- `API_BASE_URL`: LLM endpoint URL (default: `https://api.openai.com/v1`)
|
| 60 |
+
- `MODEL_NAME`: Model identifier (default: `gpt-4o-mini`)
|
| 61 |
+
- `TASK_NAME`: Task identifier (default: `farm-yield-optimization`)
|
| 62 |
+
- `BENCHMARK`: Benchmark name (default: `farmrl`)
|
| 63 |
+
- `PORT`: Server port (default: `7860`)
|
| 64 |
+
- `OPENAI_API_KEY`: Your OpenAI API key (required, no default)
|
| 65 |
+
|
| 66 |
+
### Running the API Server
|
| 67 |
+
|
| 68 |
+
Start the OpenEnv API server on your configured port:
|
| 69 |
+
|
| 70 |
+
```bash
|
| 71 |
+
uv run python -m server.app
|
| 72 |
+
```
|
| 73 |
+
|
| 74 |
+
The server will be available at `http://localhost:7860`
|
| 75 |
+
|
| 76 |
+
### Running Inference
|
| 77 |
+
|
| 78 |
+
Execute the full inference pipeline:
|
| 79 |
+
|
| 80 |
+
```bash
|
| 81 |
+
uv run python inference.py
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
This runs the agent against the environment, logging results to stdout in the standard format:
|
| 85 |
+
- `[START]` - Episode initialization
|
| 86 |
+
- `[STEP]` - Individual step results
|
| 87 |
+
- `[END]` - Episode completion with score
|
| 88 |
+
|
| 89 |
+
## Project Structure
|
| 90 |
+
|
| 91 |
+
```
|
| 92 |
+
.
|
| 93 |
+
├── api/ # REST API endpoints
|
| 94 |
+
├── env/ # FarmRL environment implementation
|
| 95 |
+
├── server/ # API server setup
|
| 96 |
+
├── tasks/ # Grading and evaluation
|
| 97 |
+
├── scripts/ # Data preprocessing utilities
|
| 98 |
+
├── reference-material/ # Documentation and examples
|
| 99 |
+
├── inference.py # Main inference script
|
| 100 |
+
├── openenv.yaml # Environment schema definition
|
| 101 |
+
├── requirements.txt # Python dependencies
|
| 102 |
+
└── farmer_advisor_dataset.csv # Agricultural training data
|
| 103 |
+
```
|
| 104 |
+
|
| 105 |
+
## Environment Specification
|
| 106 |
+
|
| 107 |
+
The environment state and action spaces are defined in `openenv.yaml`:
|
| 108 |
+
|
| 109 |
+
**Observations:**
|
| 110 |
+
- `soil_moisture`: Soil water availability (0-100%)
|
| 111 |
+
- `soil_ph`: Soil acidity (4-9)
|
| 112 |
+
- `temperature`: Environmental temperature
|
| 113 |
+
- `rainfall`: Precipitation amount (mm)
|
| 114 |
+
- `crop_stage`: Current crop growth stage
|
| 115 |
+
- `day`: Days since planting
|
| 116 |
+
|
| 117 |
+
**Actions:**
|
| 118 |
+
- `water`: Irrigation amount (0-50 mm)
|
| 119 |
+
- `fertilizer`: Fertilizer application
|
| 120 |
+
- `pesticide`: Pesticide application
|
| 121 |
+
|
| 122 |
+
## API Endpoints
|
| 123 |
+
|
| 124 |
+
- `POST /reset` - Reset environment (optional seed parameter)
|
| 125 |
+
- `POST /step` - Execute action and get next state
|
| 126 |
+
- `GET /state` - Get current environment state
|
| 127 |
+
- `GET /health` - Health check
|
| 128 |
+
|
| 129 |
+
## Data Pipeline
|
| 130 |
+
|
| 131 |
+
The project includes a preprocessing script (`scripts/add_water_variable.py`) that:
|
| 132 |
+
1. Adds a `Water_mm` column representing agent-controllable irrigation
|
| 133 |
+
2. Adjusts `Rainfall_mm` to maintain water-balance invariance
|
| 134 |
+
|
| 135 |
+
Run preprocessing:
|
| 136 |
+
```bash
|
| 137 |
+
uv run python scripts/add_water_variable.py farmer_advisor_dataset.csv
|
| 138 |
+
```
|
| 139 |
+
|
| 140 |
+
## Evaluation
|
| 141 |
+
|
| 142 |
+
The grading system (`tasks/graders.py`) evaluates agent performance based on:
|
| 143 |
+
- Crop yield optimization
|
| 144 |
+
- Sustainability metrics
|
| 145 |
+
- Action validity
|
| 146 |
+
|
| 147 |
+
## Docker
|
| 148 |
+
|
| 149 |
+
The project includes a Dockerfile for containerized deployment:
|
| 150 |
+
|
| 151 |
+
```bash
|
| 152 |
+
docker build -t farmrl-openenv .
|
| 153 |
+
docker run -p 7860:7860 farmrl-openenv
|
| 154 |
+
```
|
| 155 |
+
|
| 156 |
+
## References
|
| 157 |
+
|
| 158 |
+
- [OpenEnv Framework](https://github.com/openenv-ai/openenv)
|
| 159 |
+
- [FarmGym Simulation](https://github.com/farm-gym)
|
| 160 |
+
- Dataset: Real agricultural data with crop yield observations
|
final-requirements.md
DELETED
|
@@ -1,55 +0,0 @@
|
|
| 1 |
-
Functional Requirements:
|
| 2 |
-
|
| 3 |
-
1. Real-World Task Simulation
|
| 4 |
-
The environment must represent tasks that humans actually perform in real settings—no games
|
| 5 |
-
or toy problems.
|
| 6 |
-
Examples include email triage, code review, data cleaning, scheduling, customer support, and
|
| 7 |
-
content moderation.
|
| 8 |
-
|
| 9 |
-
2. OpenEnv Specification Compliance
|
| 10 |
-
The environment must fully implement the OpenEnv interface, including:
|
| 11 |
-
Typed Observation, Action, and Reward models using Pydantic
|
| 12 |
-
step(action) → returns (observation, reward, done, info)
|
| 13 |
-
reset() → returns the initial observation
|
| 14 |
-
state() → returns the current state
|
| 15 |
-
An openenv.yaml file containing metadata
|
| 16 |
-
The implementation must successfully pass validation via openenv validate.
|
| 17 |
-
|
| 18 |
-
3. Minimum of Three Tasks with Agent Graders
|
| 19 |
-
Provide at least three tasks, each with a clearly defined objective
|
| 20 |
-
Tasks should span increasing difficulty: easy → medium → hard
|
| 21 |
-
Each task must include a programmatic grader that assigns a score between 0.0 and
|
| 22 |
-
1.0
|
| 23 |
-
Grading criteria must be clear, deterministic, and reproducible
|
| 24 |
-
|
| 25 |
-
4. Meaningful Reward Function
|
| 26 |
-
The reward function must provide feedback throughout the task trajectory, not just at
|
| 27 |
-
completion
|
| 28 |
-
It should reward incremental progress toward the objective
|
| 29 |
-
It must penalize undesirable behaviors such as infinite loops or destructive actions
|
| 30 |
-
|
| 31 |
-
5. Baseline Inference Script
|
| 32 |
-
Include an inference script that uses the OpenAI API client to evaluate a model within
|
| 33 |
-
the environment
|
| 34 |
-
API credentials must be read from environment variables (HF_TOKEN)
|
| 35 |
-
The script should produce a reproducible baseline score across all tasks
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
Non-Functional Requirements:
|
| 39 |
-
1. Deployment on Hugging Face Spaces
|
| 40 |
-
The environment must be deployable as a containerized Hugging Face Space
|
| 41 |
-
It should be tagged with openenv
|
| 42 |
-
|
| 43 |
-
2. Containerized Execution
|
| 44 |
-
Provide a working Dockerfile
|
| 45 |
-
The environment must build and run successfully using:
|
| 46 |
-
docker build
|
| 47 |
-
docker run
|
| 48 |
-
|
| 49 |
-
3. Documentation
|
| 50 |
-
The README must include:
|
| 51 |
-
Environment overview and motivation
|
| 52 |
-
Definitions of action and observation spaces
|
| 53 |
-
Task descriptions with expected difficulty levels
|
| 54 |
-
Setup and usage instructions
|
| 55 |
-
Baseline performance scores
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inference.py
CHANGED
|
@@ -27,11 +27,11 @@ def require_env(name: str) -> str:
|
|
| 27 |
return value
|
| 28 |
|
| 29 |
|
| 30 |
-
API_BASE_URL =
|
| 31 |
-
MODEL_NAME =
|
| 32 |
-
TASK_NAME =
|
| 33 |
-
BENCHMARK =
|
| 34 |
-
OPENAI_API_KEY =
|
| 35 |
|
| 36 |
PLACEHOLDER_TOKENS = {
|
| 37 |
"your_openai_api_key_here",
|
|
|
|
| 27 |
return value
|
| 28 |
|
| 29 |
|
| 30 |
+
API_BASE_URL = os.getenv("API_BASE_URL", "https://api.openai.com/v1").strip()
|
| 31 |
+
MODEL_NAME = os.getenv("MODEL_NAME", "gpt-4o-mini").strip()
|
| 32 |
+
TASK_NAME = os.getenv("TASK_NAME", "farm-yield-optimization").strip()
|
| 33 |
+
BENCHMARK = os.getenv("BENCHMARK", "farmrl").strip()
|
| 34 |
+
OPENAI_API_KEY = require_env("OPENAI_API_KEY")
|
| 35 |
|
| 36 |
PLACEHOLDER_TOKENS = {
|
| 37 |
"your_openai_api_key_here",
|
openenv.yaml
CHANGED
|
@@ -7,6 +7,13 @@ environment:
|
|
| 7 |
step: POST /step
|
| 8 |
state: GET /state
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
observation_schema:
|
| 11 |
type: object
|
| 12 |
required:
|
|
|
|
| 7 |
step: POST /step
|
| 8 |
state: GET /state
|
| 9 |
|
| 10 |
+
defaults:
|
| 11 |
+
API_BASE_URL: https://api.openai.com/v1
|
| 12 |
+
MODEL_NAME: gpt-4o-mini
|
| 13 |
+
TASK_NAME: farm-yield-optimization
|
| 14 |
+
BENCHMARK: farmrl
|
| 15 |
+
PORT: 7860
|
| 16 |
+
|
| 17 |
observation_schema:
|
| 18 |
type: object
|
| 19 |
required:
|