Spaces:
Runtime error
Runtime error
| #!/usr/bin/env python3 | |
| """ | |
| Interact with My Open Env running on a Hugging Face Space (or any server). | |
| Usage: | |
| # After pushing, set your Space URL (replace USER with your HF username): | |
| export SPACE_URL="https://USER-my-open-env.hf.space" | |
| uv run python scripts/interact_with_space.py | |
| # Or pass URL as first argument: | |
| uv run python scripts/interact_with_space.py https://USER-my-open-env.hf.space | |
| # Local server: | |
| uv run python scripts/interact_with_space.py http://localhost:8000 | |
| """ | |
| import os | |
| import sys | |
| def main() -> None: | |
| base_url = ( | |
| os.environ.get("SPACE_URL") | |
| or (sys.argv[1] if len(sys.argv) > 1 else None) | |
| or "http://localhost:8000" | |
| ) | |
| if base_url == "http://localhost:8000": | |
| print("Using default base_url: http://localhost:8000") | |
| print("Set SPACE_URL or pass URL as first argument to use your HF Space.\n") | |
| else: | |
| print(f"Connecting to: {base_url}\n") | |
| from my_open_env import MyOpenAction, MyOpenEnv | |
| with MyOpenEnv(base_url=base_url) as env: | |
| result = env.reset() | |
| print(f"Reset: {result.observation.echoed_message}") | |
| for msg in ["Hello from the client!", "Echo test", "Done."]: | |
| result = env.step(MyOpenAction(message=msg)) | |
| print( | |
| f" → Sent: '{msg}' → Echo: '{result.observation.echoed_message}' " | |
| f"(length={result.observation.message_length}, reward={result.reward})" | |
| ) | |
| print("\nDone.") | |
| if __name__ == "__main__": | |
| main() | |