Commit
·
f230787
1
Parent(s):
f641055
Agregar interfaz de pruebas y mejorar la interfaz de Gradio con nuevas funcionalidades
Browse files
app.py
CHANGED
|
@@ -1,13 +1,57 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from tools import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
import os
|
| 5 |
|
| 6 |
load_dotenv()
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
# === GRADIO INTERFACE ===
|
| 9 |
demo = gr.TabbedInterface(
|
| 10 |
[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
gr.Interface(letter_counter, [gr.Textbox(), gr.Textbox()], gr.Textbox(), api_name="letter_counter"),
|
| 12 |
gr.Interface(prime_factors, gr.Number(), gr.JSON(), api_name="prime_factors"),
|
| 13 |
gr.Interface(roll_dice, [gr.Number(label="Faces"), gr.Number(label="Rolls")], gr.JSON(), api_name="roll_dice"),
|
|
@@ -15,22 +59,128 @@ demo = gr.TabbedInterface(
|
|
| 15 |
gr.Interface(
|
| 16 |
create_shape,
|
| 17 |
[
|
| 18 |
-
gr.Number(label="width"
|
| 19 |
-
gr.Number(label="height"
|
| 20 |
-
gr.
|
| 21 |
-
gr.
|
|
|
|
|
|
|
|
|
|
| 22 |
gr.Textbox(label="Tab ID"),
|
| 23 |
],
|
| 24 |
gr.JSON(),
|
| 25 |
api_name="create_shape"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
)
|
| 27 |
],
|
| 28 |
[
|
|
|
|
| 29 |
"Letter Counter",
|
| 30 |
"Prime Factors",
|
| 31 |
"Roll Dice",
|
| 32 |
"Coin Flip",
|
| 33 |
-
"Create Shape"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
]
|
| 35 |
)
|
| 36 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from tools.general import (
|
| 3 |
+
letter_counter,
|
| 4 |
+
prime_factors,
|
| 5 |
+
roll_dice,
|
| 6 |
+
coin_flip,
|
| 7 |
+
)
|
| 8 |
+
from tools.obr import (
|
| 9 |
+
create_shape,
|
| 10 |
+
create_token,
|
| 11 |
+
game_state,
|
| 12 |
+
move_item,
|
| 13 |
+
delete_item,
|
| 14 |
+
fill_fog,
|
| 15 |
+
clear_fog,
|
| 16 |
+
add_token_light,
|
| 17 |
+
animate_token_viewport,
|
| 18 |
+
insert_map,
|
| 19 |
+
clean_map
|
| 20 |
+
)
|
| 21 |
from dotenv import load_dotenv
|
| 22 |
import os
|
| 23 |
|
| 24 |
load_dotenv()
|
| 25 |
|
| 26 |
+
# === FUNCIÓN DE PRUEBA ===
|
| 27 |
+
def test_function(text_input, number_input):
|
| 28 |
+
"""Función de prueba que combina varias funcionalidades para testing"""
|
| 29 |
+
result = {
|
| 30 |
+
"text_analysis": letter_counter(text_input, "a"),
|
| 31 |
+
"dice_roll": roll_dice(6, number_input),
|
| 32 |
+
"coin_flip": coin_flip(number_input),
|
| 33 |
+
"input_received": {
|
| 34 |
+
"text": text_input,
|
| 35 |
+
"number": number_input
|
| 36 |
+
}
|
| 37 |
+
}
|
| 38 |
+
return result
|
| 39 |
+
|
| 40 |
# === GRADIO INTERFACE ===
|
| 41 |
demo = gr.TabbedInterface(
|
| 42 |
[
|
| 43 |
+
# Pestaña de pruebas (sin api_name)
|
| 44 |
+
gr.Interface(
|
| 45 |
+
test_function,
|
| 46 |
+
[
|
| 47 |
+
gr.Textbox(label="Texto de prueba", placeholder="Escribe algo aquí..."),
|
| 48 |
+
gr.Number(label="Número de prueba", value=3, minimum=1, maximum=10)
|
| 49 |
+
],
|
| 50 |
+
gr.JSON(label="Resultados de la prueba"),
|
| 51 |
+
title="Ventana de Pruebas",
|
| 52 |
+
description="Esta ventana es solo para hacer pruebas y no sirve como endpoint.",
|
| 53 |
+
api_name=False
|
| 54 |
+
),
|
| 55 |
gr.Interface(letter_counter, [gr.Textbox(), gr.Textbox()], gr.Textbox(), api_name="letter_counter"),
|
| 56 |
gr.Interface(prime_factors, gr.Number(), gr.JSON(), api_name="prime_factors"),
|
| 57 |
gr.Interface(roll_dice, [gr.Number(label="Faces"), gr.Number(label="Rolls")], gr.JSON(), api_name="roll_dice"),
|
|
|
|
| 59 |
gr.Interface(
|
| 60 |
create_shape,
|
| 61 |
[
|
| 62 |
+
gr.Number(label="width"),
|
| 63 |
+
gr.Number(label="height"),
|
| 64 |
+
gr.Number(label="X"),
|
| 65 |
+
gr.Number(label="Y"),
|
| 66 |
+
gr.Textbox(label="Shape Type"),
|
| 67 |
+
gr.Textbox(label="Color (hex, e.g., #ff0000)"),
|
| 68 |
+
gr.Textbox(label="Stroke Color (hex, e.g., #ff0000)"),
|
| 69 |
gr.Textbox(label="Tab ID"),
|
| 70 |
],
|
| 71 |
gr.JSON(),
|
| 72 |
api_name="create_shape"
|
| 73 |
+
),
|
| 74 |
+
gr.Interface(
|
| 75 |
+
create_token,
|
| 76 |
+
[
|
| 77 |
+
gr.Textbox(label="Name"),
|
| 78 |
+
gr.Textbox(label="Type"),
|
| 79 |
+
gr.Number(label="X"),
|
| 80 |
+
gr.Number(label="Y"),
|
| 81 |
+
gr.Number(label="Size"),
|
| 82 |
+
gr.Textbox(label="Tab ID")
|
| 83 |
+
],
|
| 84 |
+
gr.JSON(),
|
| 85 |
+
api_name="create_token"
|
| 86 |
+
),
|
| 87 |
+
gr.Interface(
|
| 88 |
+
game_state,
|
| 89 |
+
gr.Textbox(label="Tab ID"),
|
| 90 |
+
gr.JSON(),
|
| 91 |
+
api_name="game_state"
|
| 92 |
+
),
|
| 93 |
+
gr.Interface(
|
| 94 |
+
move_item,
|
| 95 |
+
[
|
| 96 |
+
gr.Textbox(label="Tab ID"),
|
| 97 |
+
gr.Textbox(label="Item ID"),
|
| 98 |
+
gr.Number(label="X"),
|
| 99 |
+
gr.Number(label="Y")
|
| 100 |
+
],
|
| 101 |
+
gr.JSON(),
|
| 102 |
+
api_name="move_item"
|
| 103 |
+
),
|
| 104 |
+
gr.Interface(
|
| 105 |
+
delete_item,
|
| 106 |
+
[
|
| 107 |
+
gr.Textbox(label="Tab ID"),
|
| 108 |
+
gr.Textbox(label="Item ID")
|
| 109 |
+
],
|
| 110 |
+
gr.JSON(),
|
| 111 |
+
api_name="delete_item"
|
| 112 |
+
),
|
| 113 |
+
gr.Interface(
|
| 114 |
+
fill_fog,
|
| 115 |
+
[
|
| 116 |
+
gr.Textbox(label="Tab ID"),
|
| 117 |
+
],
|
| 118 |
+
gr.JSON(),
|
| 119 |
+
api_name="fill_fog"
|
| 120 |
+
),
|
| 121 |
+
gr.Interface(
|
| 122 |
+
clear_fog,
|
| 123 |
+
[
|
| 124 |
+
gr.Textbox(label="Tab ID"),
|
| 125 |
+
],
|
| 126 |
+
gr.JSON(),
|
| 127 |
+
api_name="clear_fog"
|
| 128 |
+
),
|
| 129 |
+
|
| 130 |
+
gr.Interface(
|
| 131 |
+
add_token_light,
|
| 132 |
+
[
|
| 133 |
+
gr.Textbox(label="Tab ID"),
|
| 134 |
+
gr.Textbox(label="Token ID"),
|
| 135 |
+
gr.Number(label="Radius")
|
| 136 |
+
],
|
| 137 |
+
gr.JSON(),
|
| 138 |
+
api_name="add_token_light"
|
| 139 |
+
),
|
| 140 |
+
gr.Interface(
|
| 141 |
+
animate_token_viewport,
|
| 142 |
+
[
|
| 143 |
+
gr.Textbox(label="Tab ID"),
|
| 144 |
+
gr.Textbox(label="Token ID")
|
| 145 |
+
],
|
| 146 |
+
gr.JSON(),
|
| 147 |
+
api_name="animate_token_viewport"
|
| 148 |
+
),
|
| 149 |
+
gr.Interface(
|
| 150 |
+
insert_map,
|
| 151 |
+
[
|
| 152 |
+
gr.Textbox(label="Tab ID"),
|
| 153 |
+
gr.Textbox(label="Map Name")
|
| 154 |
+
],
|
| 155 |
+
gr.JSON(),
|
| 156 |
+
api_name="insert_map"
|
| 157 |
+
),
|
| 158 |
+
gr.Interface(
|
| 159 |
+
clean_map,
|
| 160 |
+
[
|
| 161 |
+
gr.Textbox(label="Tab ID")
|
| 162 |
+
],
|
| 163 |
+
gr.JSON(),
|
| 164 |
+
api_name="clean_map"
|
| 165 |
)
|
| 166 |
],
|
| 167 |
[
|
| 168 |
+
"🧪 Pruebas",
|
| 169 |
"Letter Counter",
|
| 170 |
"Prime Factors",
|
| 171 |
"Roll Dice",
|
| 172 |
"Coin Flip",
|
| 173 |
+
"Create Shape",
|
| 174 |
+
"Create Token",
|
| 175 |
+
"Game State",
|
| 176 |
+
"Move Item",
|
| 177 |
+
"Delete Item",
|
| 178 |
+
"Fill Fog",
|
| 179 |
+
"Clear Fog",
|
| 180 |
+
"Add Token Light",
|
| 181 |
+
"Animate Token Viewport",
|
| 182 |
+
"Insert Map",
|
| 183 |
+
"Clean Map"
|
| 184 |
]
|
| 185 |
)
|
| 186 |
|