Spaces:
Running
Running
Horace He
commited on
Commit
·
33dcfaf
1
Parent(s):
d1e1673
Support URL parameters
Browse files
app.py
CHANGED
|
@@ -170,8 +170,68 @@ def gradio_visualize(tiler_mn_str, tv_layout_str, dpi, max_rows, max_cols):
|
|
| 170 |
return fig
|
| 171 |
|
| 172 |
|
| 173 |
-
# Create Gradio interface
|
| 174 |
-
with gr.Blocks(title="CuTe TV Layout Visualizer"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
gr.Markdown("# CuTe TV Layout Visualizer")
|
| 176 |
gr.Markdown("Visualize thread/value (T/V) layouts for CuTe tensor operations.")
|
| 177 |
|
|
@@ -181,19 +241,21 @@ with gr.Blocks(title="CuTe TV Layout Visualizer") as demo:
|
|
| 181 |
tiler_mn = gr.Textbox(
|
| 182 |
label="Tiler Dimensions (M, N)",
|
| 183 |
value="(8, 8)",
|
| 184 |
-
placeholder="(8, 8)"
|
|
|
|
| 185 |
)
|
| 186 |
tv_layout = gr.Textbox(
|
| 187 |
label="TV Layout",
|
| 188 |
value="((2, 2, 2), (2, 2, 2)):((1, 16, 4), (8, 2, 32))",
|
| 189 |
-
lines=2
|
|
|
|
| 190 |
)
|
| 191 |
|
| 192 |
-
dpi = gr.Number(label="DPI", value=200, precision=0)
|
| 193 |
-
max_rows = gr.Number(label="Max Rows (leave empty for no limit)", value=None, precision=0)
|
| 194 |
-
max_cols = gr.Number(label="Max Cols (leave empty for no limit)", value=None, precision=0)
|
| 195 |
|
| 196 |
-
visualize_btn = gr.Button("Visualize", variant="primary")
|
| 197 |
|
| 198 |
with gr.Column():
|
| 199 |
output_plot = gr.Plot(label="TV Layout Visualization")
|
|
|
|
| 170 |
return fig
|
| 171 |
|
| 172 |
|
| 173 |
+
# Create Gradio interface with URL parameter support
|
| 174 |
+
with gr.Blocks(title="CuTe TV Layout Visualizer", js="""
|
| 175 |
+
function() {
|
| 176 |
+
const params = new URLSearchParams(window.location.search);
|
| 177 |
+
|
| 178 |
+
// Get all parameter elements
|
| 179 |
+
const inputs = {
|
| 180 |
+
'tiler_mn': params.get('tiler_mn'),
|
| 181 |
+
'tv_layout': params.get('tv_layout'),
|
| 182 |
+
'dpi': params.get('dpi'),
|
| 183 |
+
'max_rows': params.get('max_rows'),
|
| 184 |
+
'max_cols': params.get('max_cols')
|
| 185 |
+
};
|
| 186 |
+
|
| 187 |
+
// Update input fields if parameters exist
|
| 188 |
+
setTimeout(() => {
|
| 189 |
+
if (inputs.tiler_mn) {
|
| 190 |
+
const elem = document.querySelector('#tiler_mn textarea, #tiler_mn input');
|
| 191 |
+
if (elem) {
|
| 192 |
+
elem.value = decodeURIComponent(inputs.tiler_mn);
|
| 193 |
+
elem.dispatchEvent(new Event('input', { bubbles: true }));
|
| 194 |
+
}
|
| 195 |
+
}
|
| 196 |
+
if (inputs.tv_layout) {
|
| 197 |
+
const elem = document.querySelector('#tv_layout textarea, #tv_layout input');
|
| 198 |
+
if (elem) {
|
| 199 |
+
elem.value = decodeURIComponent(inputs.tv_layout);
|
| 200 |
+
elem.dispatchEvent(new Event('input', { bubbles: true }));
|
| 201 |
+
}
|
| 202 |
+
}
|
| 203 |
+
if (inputs.dpi) {
|
| 204 |
+
const elem = document.querySelector('#dpi input');
|
| 205 |
+
if (elem) {
|
| 206 |
+
elem.value = inputs.dpi;
|
| 207 |
+
elem.dispatchEvent(new Event('input', { bubbles: true }));
|
| 208 |
+
}
|
| 209 |
+
}
|
| 210 |
+
if (inputs.max_rows) {
|
| 211 |
+
const elem = document.querySelector('#max_rows input');
|
| 212 |
+
if (elem) {
|
| 213 |
+
elem.value = inputs.max_rows;
|
| 214 |
+
elem.dispatchEvent(new Event('input', { bubbles: true }));
|
| 215 |
+
}
|
| 216 |
+
}
|
| 217 |
+
if (inputs.max_cols) {
|
| 218 |
+
const elem = document.querySelector('#max_cols input');
|
| 219 |
+
if (elem) {
|
| 220 |
+
elem.value = inputs.max_cols;
|
| 221 |
+
elem.dispatchEvent(new Event('input', { bubbles: true }));
|
| 222 |
+
}
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
// Auto-trigger visualization if any params exist
|
| 226 |
+
if (Object.values(inputs).some(v => v !== null)) {
|
| 227 |
+
setTimeout(() => {
|
| 228 |
+
const btn = document.querySelector('button.primary');
|
| 229 |
+
if (btn) btn.click();
|
| 230 |
+
}, 500);
|
| 231 |
+
}
|
| 232 |
+
}, 1000);
|
| 233 |
+
}
|
| 234 |
+
""") as demo:
|
| 235 |
gr.Markdown("# CuTe TV Layout Visualizer")
|
| 236 |
gr.Markdown("Visualize thread/value (T/V) layouts for CuTe tensor operations.")
|
| 237 |
|
|
|
|
| 241 |
tiler_mn = gr.Textbox(
|
| 242 |
label="Tiler Dimensions (M, N)",
|
| 243 |
value="(8, 8)",
|
| 244 |
+
placeholder="(8, 8)",
|
| 245 |
+
elem_id="tiler_mn"
|
| 246 |
)
|
| 247 |
tv_layout = gr.Textbox(
|
| 248 |
label="TV Layout",
|
| 249 |
value="((2, 2, 2), (2, 2, 2)):((1, 16, 4), (8, 2, 32))",
|
| 250 |
+
lines=2,
|
| 251 |
+
elem_id="tv_layout"
|
| 252 |
)
|
| 253 |
|
| 254 |
+
dpi = gr.Number(label="DPI", value=200, precision=0, elem_id="dpi")
|
| 255 |
+
max_rows = gr.Number(label="Max Rows (leave empty for no limit)", value=None, precision=0, elem_id="max_rows")
|
| 256 |
+
max_cols = gr.Number(label="Max Cols (leave empty for no limit)", value=None, precision=0, elem_id="max_cols")
|
| 257 |
|
| 258 |
+
visualize_btn = gr.Button("Visualize", variant="primary", elem_classes=["primary"])
|
| 259 |
|
| 260 |
with gr.Column():
|
| 261 |
output_plot = gr.Plot(label="TV Layout Visualization")
|