Upload folder using huggingface_hub
Browse files- .gitignore +9 -0
- Dockerfile +29 -0
- README.md +50 -5
- __init__.py +2 -0
- client.py +6 -0
- models.py +23 -0
- openenv.yaml +8 -0
- server/Dockerfile +20 -0
- server/__init__.py +2 -0
- server/app.py +41 -0
- server/requirements.txt +5 -0
.gitignore
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__pycache__/
|
| 2 |
+
*.pyc
|
| 3 |
+
.venv/
|
| 4 |
+
env/
|
| 5 |
+
.env
|
| 6 |
+
hf-staging/
|
| 7 |
+
.DS_Store
|
| 8 |
+
|
| 9 |
+
|
Dockerfile
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 2 |
+
# All rights reserved.
|
| 3 |
+
#
|
| 4 |
+
# This source code is licensed under the BSD-style license found in the
|
| 5 |
+
# LICENSE file in the root directory of this source tree.
|
| 6 |
+
ARG BASE_IMAGE=ghcr.io/meta-pytorch/openenv-base:latest
|
| 7 |
+
FROM ghcr.io/meta-pytorch/openenv-base:latest
|
| 8 |
+
|
| 9 |
+
WORKDIR /app
|
| 10 |
+
|
| 11 |
+
COPY . /app
|
| 12 |
+
|
| 13 |
+
RUN pip install --no-cache-dir -r server/requirements.txt
|
| 14 |
+
|
| 15 |
+
# Copy only what's needed for this environment
|
| 16 |
+
COPY ../* /app/myenv
|
| 17 |
+
|
| 18 |
+
# Copy README for web interface documentation
|
| 19 |
+
COPY ../README.md /app/README.md
|
| 20 |
+
|
| 21 |
+
# Health check
|
| 22 |
+
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
| 23 |
+
CMD curl -f http://localhost:8000/health || exit 1
|
| 24 |
+
|
| 25 |
+
# Run the FastAPI server
|
| 26 |
+
ENV ENABLE_WEB_INTERFACE=true
|
| 27 |
+
ENV PYTHONPATH=/app
|
| 28 |
+
|
| 29 |
+
CMD ["uvicorn", "server.app:app", "--host", "0.0.0.0", "--port", "8000"]
|
README.md
CHANGED
|
@@ -1,10 +1,55 @@
|
|
| 1 |
---
|
| 2 |
-
title: Myenv
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Myenv Environment Server
|
| 3 |
+
emoji: 🐀
|
| 4 |
+
colorFrom: yellow
|
| 5 |
+
colorTo: blue
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
+
app_port: 8000
|
| 9 |
+
base_path: /web
|
| 10 |
+
tags:
|
| 11 |
+
- openenv
|
| 12 |
---
|
| 13 |
|
| 14 |
+
# Myenv Environment Server
|
| 15 |
+
|
| 16 |
+
FastAPI server for myenv environment powered by Meta's OpenEnv.
|
| 17 |
+
|
| 18 |
+
## About
|
| 19 |
+
|
| 20 |
+
This Space provides a containerized environment for myenv interactions.
|
| 21 |
+
Built with FastAPI and OpenEnv framework.
|
| 22 |
+
|
| 23 |
+
## Web Interface
|
| 24 |
+
|
| 25 |
+
This deployment includes an interactive web interface for exploring the environment:
|
| 26 |
+
- **HumanAgent Interface**: Interact with the environment using a web form
|
| 27 |
+
- **State Observer**: Real-time view of environment state and action history
|
| 28 |
+
- **Live Updates**: WebSocket-based real-time updates
|
| 29 |
+
|
| 30 |
+
Access the web interface at: `/web`
|
| 31 |
+
|
| 32 |
+
## API Documentation
|
| 33 |
+
|
| 34 |
+
Visit `/docs` for interactive API documentation.
|
| 35 |
+
|
| 36 |
+
## Health Check
|
| 37 |
+
|
| 38 |
+
The environment provides a health check endpoint at `/health`.
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
# myenv Environment
|
| 42 |
+
|
| 43 |
+
This is a minimal OpenEnv environment scaffold.
|
| 44 |
+
|
| 45 |
+
## Run locally
|
| 46 |
+
|
| 47 |
+
```bash
|
| 48 |
+
uvicorn server.app:app --reload
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
## Push to Hugging Face Spaces
|
| 52 |
+
|
| 53 |
+
```bash
|
| 54 |
+
openenv push --repo-id <you>/myenv
|
| 55 |
+
```
|
__init__.py
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
client.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Client stub for myenv environment."""
|
| 2 |
+
|
| 3 |
+
class myenvEnv:
|
| 4 |
+
pass
|
| 5 |
+
|
| 6 |
+
|
models.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from dataclasses import dataclass, field
|
| 2 |
+
from typing import Any
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
@dataclass
|
| 6 |
+
class Action:
|
| 7 |
+
"""Base Action for myenv."""
|
| 8 |
+
pass
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
@dataclass
|
| 12 |
+
class Observation:
|
| 13 |
+
"""Base Observation for myenv."""
|
| 14 |
+
message: str = ""
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
@dataclass
|
| 18 |
+
class State:
|
| 19 |
+
"""Episode state."""
|
| 20 |
+
episode_id: str = ""
|
| 21 |
+
step_count: int = 0
|
| 22 |
+
|
| 23 |
+
|
openenv.yaml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
spec_version: 1
|
| 2 |
+
name: myenv
|
| 3 |
+
type: space
|
| 4 |
+
runtime: fastapi
|
| 5 |
+
app: envs.myenv.server.app:app
|
| 6 |
+
port: 8000
|
| 7 |
+
|
| 8 |
+
|
server/Dockerfile
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 2 |
+
# All rights reserved.
|
| 3 |
+
#
|
| 4 |
+
# This source code is licensed under the BSD-style license found in the
|
| 5 |
+
# LICENSE file in the root directory of this source tree.
|
| 6 |
+
ARG BASE_IMAGE=ghcr.io/meta-pytorch/openenv-base:latest
|
| 7 |
+
FROM ${BASE_IMAGE}
|
| 8 |
+
|
| 9 |
+
# Copy only what's needed for this environment
|
| 10 |
+
COPY ../* /app/myenv
|
| 11 |
+
|
| 12 |
+
# Copy README for web interface documentation
|
| 13 |
+
COPY ../README.md /app/README.md
|
| 14 |
+
|
| 15 |
+
# Health check
|
| 16 |
+
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
| 17 |
+
CMD curl -f http://localhost:8000/health || exit 1
|
| 18 |
+
|
| 19 |
+
# Run the FastAPI server
|
| 20 |
+
CMD ["uvicorn", "envs.myenv.server.app:app", "--host", "0.0.0.0", "--port", "8000"]
|
server/__init__.py
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
server/app.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from dataclasses import dataclass
|
| 2 |
+
from typing import Any
|
| 3 |
+
|
| 4 |
+
try:
|
| 5 |
+
from openenv_core.env_server.interfaces import Environment
|
| 6 |
+
from openenv_core.env_server.http_server import create_app
|
| 7 |
+
except Exception as e: # pragma: no cover
|
| 8 |
+
raise ImportError(
|
| 9 |
+
"openenv_core is required for the web interface. Install template deps with '\n"
|
| 10 |
+
" pip install -r server/requirements.txt\n'"
|
| 11 |
+
) from e
|
| 12 |
+
|
| 13 |
+
from models import Action, Observation, State
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class TemplateEnvironment(Environment):
|
| 17 |
+
"""Minimal example environment for myenv."""
|
| 18 |
+
|
| 19 |
+
def __init__(self) -> None:
|
| 20 |
+
self._state: State = State()
|
| 21 |
+
|
| 22 |
+
def reset(self) -> Observation:
|
| 23 |
+
self._state = State(step_count=0)
|
| 24 |
+
return Observation(message="ready")
|
| 25 |
+
|
| 26 |
+
def step(self, action: Action) -> Observation:
|
| 27 |
+
# Echo-style placeholder behavior
|
| 28 |
+
payload = getattr(action, "__dict__", {})
|
| 29 |
+
text = str(payload) if payload else ""
|
| 30 |
+
self._state.step_count += 1
|
| 31 |
+
return Observation(message=f"echo: {text}")
|
| 32 |
+
|
| 33 |
+
@property
|
| 34 |
+
def state(self) -> State:
|
| 35 |
+
return self._state
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
env = TemplateEnvironment()
|
| 39 |
+
app = create_app(env, Action, Observation, env_name="myenv")
|
| 40 |
+
|
| 41 |
+
|
server/requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
uvicorn
|
| 3 |
+
openenv-core>=0.1.0
|
| 4 |
+
|
| 5 |
+
|