File size: 1,714 Bytes
5a811e2
7a789a0
 
 
 
 
5a811e2
7a789a0
 
 
5a811e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7a789a0
 
 
5a811e2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""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  # noqa: E402

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()