File size: 5,524 Bytes
7786921
f230787
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b3ea2a5
102d44d
 
18f4e71
a585ed2
102d44d
92cc575
18f4e71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92cc575
 
18f4e71
 
f230787
 
b3ea2a5
f230787
18f4e71
 
 
e23350c
f230787
92cc575
 
ab18fdf
a585ed2
 
 
 
f230787
 
 
 
 
 
 
a585ed2
 
 
 
f230787
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e584cde
f230787
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a585ed2
18f4e71
 
 
92cc575
ab18fdf
 
a585ed2
f230787
 
 
 
 
 
 
 
 
 
 
92cc575
7786921
 
e92200e
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import gradio as gr
from tools.general import (
    letter_counter, 
    prime_factors, 
    roll_dice, 
    coin_flip, 
)
from tools.obr import (
    create_shape,
    create_token,
    game_state,
    move_item,
    delete_item,
    fill_fog,
    clear_fog,
    add_token_light,
    animate_token_viewport,
    insert_map,
    clean_map
)
from tools.test import test_function
from dotenv import load_dotenv
import os
import re

load_dotenv()

with open("README.md", "r", encoding="utf-8") as f:
    readme = f.read()
    if readme.startswith("---"):
        parts = readme.split("---", 2)
        if len(parts) >= 3:
            readme = parts[2]

html_blocks = re.findall(r'```html\n(.*?)\n```', readme, re.DOTALL)
for i, html_block in enumerate(html_blocks):
    readme = readme.replace(f"```html\n{html_block}\n```", f"{{HTML_BLOCK_{i}}}")

with gr.Blocks() as intro_demo:
    parts = re.split(r'({HTML_BLOCK_\d+})', readme)
    
    for part in parts:
        if part.startswith("{HTML_BLOCK_"):
            block_idx = int(part.replace("{HTML_BLOCK_", "").replace("}", ""))
            gr.HTML(html_blocks[block_idx])
        else:
            if part.strip():
                gr.Markdown(part)

# === GRADIO INTERFACE ===
demo = gr.TabbedInterface(
    [   
        intro_demo,        gr.Interface(
            test_function,
            [
                gr.Textbox(label="Tab ID"),
            ],
            gr.JSON(label="Test Results"),
            title="OBR Test Window",
            description="This window demonstrates all available OwlBear Rodeo functionalities.",
            api_name=False
        ),
        gr.Interface(letter_counter, [gr.Textbox(), gr.Textbox()], gr.Textbox(), api_name="letter_counter"),
        gr.Interface(prime_factors, gr.Number(), gr.JSON(), api_name="prime_factors"),
        gr.Interface(roll_dice, [gr.Number(label="Faces"), gr.Number(label="Rolls")], gr.JSON(), api_name="roll_dice"),
        gr.Interface(coin_flip, gr.Number(label="Flips"), gr.JSON(), api_name="coin_flip"),
        gr.Interface(
            create_shape,
            [
                gr.Number(label="width"),
                gr.Number(label="height"),
                gr.Number(label="X"),
                gr.Number(label="Y"),
                gr.Textbox(label="Shape Type"),
                gr.Textbox(label="Color (hex, e.g., #ff0000)"),
                gr.Textbox(label="Stroke Color (hex, e.g., #ff0000)"),
                gr.Textbox(label="Tab ID"),
            ],
            gr.JSON(),
            api_name="create_shape"
        ),
        gr.Interface(
            create_token,
            [
                gr.Textbox(label="Name"),
                gr.Textbox(label="Type"),
                gr.Number(label="X"),
                gr.Number(label="Y"),
                gr.Number(label="Size"),
                gr.Textbox(label="Tab ID")
            ],
            gr.JSON(),
            api_name="create_token"
        ),
        gr.Interface(
            game_state,
            gr.Textbox(label="Tab ID"),
            gr.JSON(),
            api_name=False  # Removed because it is forced
        ),
        gr.Interface(
            move_item,
            [
                gr.Textbox(label="Tab ID"),
                gr.Textbox(label="Item ID"),
                gr.Number(label="X"),
                gr.Number(label="Y")
            ],
            gr.JSON(),
            api_name="move_item"
        ),
        gr.Interface(
            delete_item,
            [
                gr.Textbox(label="Tab ID"),
                gr.Textbox(label="Item ID")
            ],
            gr.JSON(),
            api_name="delete_item"
        ),
        gr.Interface(
            fill_fog,
            [
                gr.Textbox(label="Tab ID"),
            ],
            gr.JSON(),
            api_name="fill_fog"
        ),
        gr.Interface(
            clear_fog,
            [
                gr.Textbox(label="Tab ID"),
            ],
            gr.JSON(),
            api_name="clear_fog"
        ),

        gr.Interface(
            add_token_light,
            [
                gr.Textbox(label="Tab ID"),
                gr.Textbox(label="Token ID"),
                gr.Number(label="Radius")
            ],
            gr.JSON(),
            api_name="add_token_light"
        ),
        gr.Interface(
            animate_token_viewport,
            [
                gr.Textbox(label="Tab ID"),
                gr.Textbox(label="Token ID")
            ],
            gr.JSON(),
            api_name="animate_token_viewport"
        ),
        gr.Interface(
            insert_map,
            [
                gr.Textbox(label="Tab ID"),
                gr.Textbox(label="Map Name")
            ],
            gr.JSON(),
            api_name="insert_map"
        ),
        gr.Interface(
            clean_map,
            [
                gr.Textbox(label="Tab ID")
            ],
            gr.JSON(),
            api_name="clean_map"
        )
    ],    [
        "🧙‍♂️ Introduction",
        "🧪 Tests",
        "Letter Counter",
        "Prime Factors",
        "Roll Dice",
        "Coin Flip",
        "Create Shape",
        "Create Token",
        "Game State",
        "Move Item",
        "Delete Item",
        "Fill Fog",
        "Clear Fog",
        "Add Token Light",
        "Animate Token Viewport",
        "Insert Map",
        "Clean Map"
    ]
)

demo.launch(mcp_server=True,server_port=int(os.getenv("GRADIO_PORT", 7860)),ssl_verify=False)