| """Hugging Face Space entry point - gr.Server with custom HTML frontend.""" |
|
|
| from __future__ import annotations |
|
|
| import os |
| import sys |
| from pathlib import Path |
|
|
| sys.path.insert(0, os.path.join(os.path.dirname(__file__), "src")) |
|
|
| from fastapi.responses import FileResponse |
| from fastapi.staticfiles import StaticFiles |
| from gradio import Server |
|
|
| from jailbreak_dojo.game_service import GameRuntime |
|
|
| STATIC = Path(__file__).parent / "static" |
| runtime = GameRuntime() |
|
|
| app = Server(title="Whisperkey") |
| app.mount("/assets", StaticFiles(directory=STATIC), name="assets") |
|
|
|
|
| @app.get("/") |
| async def homepage(): |
| return FileResponse(STATIC / "index.html") |
|
|
|
|
| @app.api(name="init_game") |
| def init_game() -> dict: |
| return runtime.init_game() |
|
|
|
|
| @app.api(name="set_model") |
| def set_model(session_id: str, model_id: str) -> dict: |
| return runtime.set_model(session_id, model_id) |
|
|
|
|
| @app.api(name="send_message") |
| def send_message(session_id: str, message: str, player_name: str = "") -> dict: |
| return runtime.send(session_id, message, player_name) |
|
|
|
|
| @app.api(name="submit_guess") |
| def submit_guess(session_id: str, guess: str, player_name: str = "") -> dict: |
| return runtime.guess(session_id, guess, player_name) |
|
|
|
|
| @app.api(name="restart_level") |
| def restart_level(session_id: str) -> dict: |
| return runtime.restart_level(session_id) |
|
|
|
|
| @app.api(name="restart_game") |
| def restart_game(session_id: str) -> dict: |
| return runtime.restart_game(session_id) |
|
|
|
|
| @app.api(name="concede") |
| def concede(session_id: str) -> dict: |
| return runtime.concede(session_id) |
|
|
|
|
| @app.api(name="get_leaderboard") |
| def get_leaderboard() -> list[list]: |
| return runtime.leaderboard() |
|
|
|
|
| if __name__ == "__main__": |
| app.launch() |
|
|