
Actualizar README.md con secciones de demostración y arquitectura, y mejorar la interfaz de usuario en app.py para manejar bloques HTML. También se corrigen comentarios y traducciones en obr.py y test.py.
18f4e71
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) | |