Spaces:
Build error
Build error
Upload folder using huggingface_hub
Browse files- src/connect4_backend.egg-info/PKG-INFO +42 -0
- src/connect4_backend.egg-info/SOURCES.txt +11 -0
- src/connect4_backend.egg-info/dependency_links.txt +1 -0
- src/connect4_backend.egg-info/requires.txt +11 -0
- src/connect4_backend.egg-info/top_level.txt +4 -0
- src/create_app.py +20 -16
- src/huggingface/huggingface_client.py +1 -1
src/connect4_backend.egg-info/PKG-INFO
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Metadata-Version: 2.1
|
2 |
+
Name: connect4-backend
|
3 |
+
Version: 0.0.1
|
4 |
+
Author: Clement Gohlke
|
5 |
+
Classifier: Programming Language :: Python :: 3
|
6 |
+
Classifier: License :: OSI Approved :: MIT License
|
7 |
+
Classifier: Operating System :: OS Independent
|
8 |
+
Requires-Python: >=3.11
|
9 |
+
Description-Content-Type: text/markdown
|
10 |
+
Requires-Dist: tensordict@ git+https://github.com/pytorch/tensordict.git@c3caa7612275306ce72697a82d5252681ddae0ab
|
11 |
+
Requires-Dist: torchrl@ git+https://github.com/pytorch/rl.git@1bb192e0f3ad9e7b8c6fa769bfa3bb9d82ca4f29
|
12 |
+
Requires-Dist: litrl~=0.0.9
|
13 |
+
Requires-Dist: fastapi==0.104.1
|
14 |
+
Requires-Dist: uvicorn==0.25.0
|
15 |
+
Requires-Dist: moviepy==1.0.3
|
16 |
+
Provides-Extra: test
|
17 |
+
Requires-Dist: pytest==7.4.4; extra == "test"
|
18 |
+
Requires-Dist: mypy==1.8.0; extra == "test"
|
19 |
+
Requires-Dist: httpx==0.26.0; extra == "test"
|
20 |
+
|
21 |
+
---
|
22 |
+
title: Connect4
|
23 |
+
emoji: 🌐
|
24 |
+
colorFrom: blue
|
25 |
+
colorTo: yellow
|
26 |
+
sdk: docker
|
27 |
+
pinned: false
|
28 |
+
license: mit
|
29 |
+
---
|
30 |
+
|
31 |
+
frontend adapted from [github](https://github.com/jprioses/connect-four-game)
|
32 |
+
|
33 |
+
Check out the configuration reference at [huggingface](https://huggingface.co/docs/hub/spaces-config-reference)
|
34 |
+
|
35 |
+
## TODO
|
36 |
+
|
37 |
+
link to github repo
|
38 |
+
|
39 |
+
test block forced move
|
40 |
+
|
41 |
+
Connect to AWS database https://aws.amazon.com/rds/?p=ft&c=db&z=3
|
42 |
+
using alembic and sqlmodel
|
src/connect4_backend.egg-info/SOURCES.txt
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
README.md
|
2 |
+
pyproject.toml
|
3 |
+
src/__init__.py
|
4 |
+
src/app_state.py
|
5 |
+
src/create_app.py
|
6 |
+
src/typing.py
|
7 |
+
src/connect4_backend.egg-info/PKG-INFO
|
8 |
+
src/connect4_backend.egg-info/SOURCES.txt
|
9 |
+
src/connect4_backend.egg-info/dependency_links.txt
|
10 |
+
src/connect4_backend.egg-info/requires.txt
|
11 |
+
src/connect4_backend.egg-info/top_level.txt
|
src/connect4_backend.egg-info/dependency_links.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
|
src/connect4_backend.egg-info/requires.txt
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
tensordict@ git+https://github.com/pytorch/tensordict.git@c3caa7612275306ce72697a82d5252681ddae0ab
|
2 |
+
torchrl@ git+https://github.com/pytorch/rl.git@1bb192e0f3ad9e7b8c6fa769bfa3bb9d82ca4f29
|
3 |
+
litrl~=0.0.9
|
4 |
+
fastapi==0.104.1
|
5 |
+
uvicorn==0.25.0
|
6 |
+
moviepy==1.0.3
|
7 |
+
|
8 |
+
[test]
|
9 |
+
pytest==7.4.4
|
10 |
+
mypy==1.8.0
|
11 |
+
httpx==0.26.0
|
src/connect4_backend.egg-info/top_level.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
__init__
|
2 |
+
app_state
|
3 |
+
create_app
|
4 |
+
typing
|
src/create_app.py
CHANGED
@@ -10,10 +10,17 @@ from fastapi.middleware.cors import CORSMiddleware
|
|
10 |
from fastapi.responses import JSONResponse
|
11 |
from litrl.env.connect_four import Board
|
12 |
from loguru import logger
|
13 |
-
from fastapi.responses import StreamingResponse
|
14 |
-
from moviepy.editor import VideoFileClip
|
15 |
from src.app_state import AppState
|
16 |
from src.typing import CpuConfig
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
|
19 |
def create_app() -> FastAPI:
|
@@ -33,9 +40,8 @@ def create_app() -> FastAPI:
|
|
33 |
def bot_action(
|
34 |
env_id: SingleAgentId,
|
35 |
) -> str:
|
36 |
-
env = make(id=env_id, render_mode="rgb_array")
|
37 |
env = RecordVideo(
|
38 |
-
env=
|
39 |
video_folder="tmp",
|
40 |
)
|
41 |
env.reset(seed=123)
|
@@ -46,14 +52,17 @@ def create_app() -> FastAPI:
|
|
46 |
_, _, terminated, truncated, _ = env.step(action=action)
|
47 |
env.render()
|
48 |
env.video_recorder.close()
|
|
|
49 |
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
|
|
55 |
|
56 |
-
@app.get(path=f"/
|
57 |
def bot_action(
|
58 |
env_id: SingleAgentId,
|
59 |
) -> str:
|
@@ -70,12 +79,7 @@ def create_app() -> FastAPI:
|
|
70 |
_, _, terminated, truncated, _ = env.step(action=action)
|
71 |
env.render()
|
72 |
env.video_recorder.close()
|
73 |
-
|
74 |
-
mp4_path = Path(env.video_recorder.path)
|
75 |
-
video_clip = VideoFileClip(str(mp4_path))
|
76 |
-
gif_path = mp4_path.with_suffix(".gif")
|
77 |
-
video_clip.write_gif(str(gif_path))#, fps=30) # TODO check fps
|
78 |
-
return FileResponse(str(gif_path), media_type="image/gif")
|
79 |
|
80 |
@app.exception_handler(exc_class_or_status_code=RequestValidationError)
|
81 |
async def validation_exception_handler(
|
|
|
10 |
from fastapi.responses import JSONResponse
|
11 |
from litrl.env.connect_four import Board
|
12 |
from loguru import logger
|
13 |
+
from fastapi.responses import StreamingResponse
|
|
|
14 |
from src.app_state import AppState
|
15 |
from src.typing import CpuConfig
|
16 |
+
from src.huggingface.huggingface_client import HuggingFaceClient
|
17 |
+
|
18 |
+
def stream_mp4(mp4_path: Path) -> StreamingResponse:
|
19 |
+
def iter_file()-> Generator[bytes, Any, None]:
|
20 |
+
with mp4_path.open(mode="rb") as env_file:
|
21 |
+
yield from env_file
|
22 |
+
|
23 |
+
return StreamingResponse(content=iter_file(), media_type="video/mp4")
|
24 |
|
25 |
|
26 |
def create_app() -> FastAPI:
|
|
|
40 |
def bot_action(
|
41 |
env_id: SingleAgentId,
|
42 |
) -> str:
|
|
|
43 |
env = RecordVideo(
|
44 |
+
env=make(id=env_id, render_mode="rgb_array"),
|
45 |
video_folder="tmp",
|
46 |
)
|
47 |
env.reset(seed=123)
|
|
|
52 |
_, _, terminated, truncated, _ = env.step(action=action)
|
53 |
env.render()
|
54 |
env.video_recorder.close()
|
55 |
+
return stream_mp4(mp4_path=Path(env.video_recorder.path))
|
56 |
|
57 |
+
@app.get(path=f"/hfmp4")
|
58 |
+
def fh_stream(
|
59 |
+
env_id: SingleAgentId,
|
60 |
+
hf_client: Annotated[HuggingFaceClient, Depends(dependency=HuggingFaceClient)],
|
61 |
+
) -> StreamingResponse:
|
62 |
+
hf_client.mp4_paths[env_id]
|
63 |
+
return stream_mp4(mp4_path=hf_client.mp4_paths[env_id])
|
64 |
|
65 |
+
@app.get(path=f"/mp4")
|
66 |
def bot_action(
|
67 |
env_id: SingleAgentId,
|
68 |
) -> str:
|
|
|
79 |
_, _, terminated, truncated, _ = env.step(action=action)
|
80 |
env.render()
|
81 |
env.video_recorder.close()
|
82 |
+
return stream_mp4(mp4_path=Path(env.video_recorder.path))
|
|
|
|
|
|
|
|
|
|
|
83 |
|
84 |
@app.exception_handler(exc_class_or_status_code=RequestValidationError)
|
85 |
async def validation_exception_handler(
|
src/huggingface/huggingface_client.py
CHANGED
@@ -5,7 +5,7 @@ from .get_files import get_mp4_paths
|
|
5 |
from .get_environments import get_environments
|
6 |
|
7 |
|
8 |
-
class
|
9 |
def __init__(self) -> None:
|
10 |
login( # type: ignore[no-untyped-call]
|
11 |
token=os.environ.get("HUGGINGFACE_TOKEN"),
|
|
|
5 |
from .get_environments import get_environments
|
6 |
|
7 |
|
8 |
+
class HuggingFaceClient:
|
9 |
def __init__(self) -> None:
|
10 |
login( # type: ignore[no-untyped-call]
|
11 |
token=os.environ.get("HUGGINGFACE_TOKEN"),
|