Spaces:
Running
Running
Update ui_generators.py
Browse files- ui_generators.py +63 -40
ui_generators.py
CHANGED
@@ -308,51 +308,74 @@ def run_follower_stats_tab_display(token_state):
|
|
308 |
|
309 |
|
310 |
# --- NEW UI GENERATION LOGIC FOR ANALYTICS TAB ---
|
311 |
-
def
|
312 |
"""
|
313 |
-
Creates a Gradio
|
314 |
-
and
|
|
|
315 |
"""
|
316 |
-
# This
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
insights_markdown_ui = gr.Markdown(f"Click 💣 for insights on {label}...") # Placeholder text
|
326 |
-
return plot_component, bomb_button, insights_col_ui, insights_markdown_ui
|
327 |
-
|
328 |
-
def build_analytics_tab_ui_components(plot_configs):
|
329 |
"""
|
330 |
-
Builds
|
331 |
-
This function should be called within the "Analytics" TabItem context in app.py
|
332 |
-
|
|
|
333 |
"""
|
334 |
-
logging.info(f"Building
|
335 |
-
plot_ui_objects = {} # Stores {"plot_id": {"
|
336 |
|
337 |
current_section_title = ""
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
#
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
"
|
353 |
-
|
354 |
-
|
355 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
356 |
|
357 |
-
logging.info(f"Finished building
|
358 |
return plot_ui_objects
|
|
|
308 |
|
309 |
|
310 |
# --- NEW UI GENERATION LOGIC FOR ANALYTICS TAB ---
|
311 |
+
def create_analytics_plot_panel(label, plot_id_str):
|
312 |
"""
|
313 |
+
Creates a Gradio Column representing a single plot panel.
|
314 |
+
This panel contains the plot and its associated "bomb" button to the right.
|
315 |
+
Returns the panel (gr.Column), the plot component, and the bomb button.
|
316 |
"""
|
317 |
+
with gr.Column() as panel_col: # This is the component that will go into the two-column rows
|
318 |
+
with gr.Row(equal_height=False, variant="panel"): # A sub-row for plot and button
|
319 |
+
with gr.Column(scale=8): # Adjust scale as needed for plot vs button
|
320 |
+
plot_component = gr.Plot(label=label)
|
321 |
+
with gr.Column(scale=2, min_width=70, vertical_alignment="center"): # min_width for button, try to center vertically
|
322 |
+
bomb_button = gr.Button("💣", variant="secondary", size="sm", elem_id=f"bomb_{plot_id_str}")
|
323 |
+
return panel_col, plot_component, bomb_button
|
324 |
+
|
325 |
+
def build_analytics_tab_plot_area(plot_configs):
|
|
|
|
|
|
|
|
|
326 |
"""
|
327 |
+
Builds the main plot area for the Analytics tab, arranging plot panels into rows of two.
|
328 |
+
This function should be called within the "Analytics" TabItem context in app.py,
|
329 |
+
specifically within the main column designated for plots.
|
330 |
+
Returns a dictionary of plot UI objects.
|
331 |
"""
|
332 |
+
logging.info(f"Building plot area for {len(plot_configs)} analytics plots.")
|
333 |
+
plot_ui_objects = {} # Stores {"plot_id": {"plot_component": gr.Plot, "bomb_button": gr.Button, "label": str}}
|
334 |
|
335 |
current_section_title = ""
|
336 |
+
|
337 |
+
# Iterate through plot_configs to create sections and then rows of plots
|
338 |
+
for i in range(0, len(plot_configs), 2): # Process in pairs for two plots per row
|
339 |
+
# Handle section header
|
340 |
+
# Check if the section of the first plot in the potential pair is new
|
341 |
+
if plot_configs[i]["section"] != current_section_title:
|
342 |
+
current_section_title = plot_configs[i]["section"]
|
343 |
+
gr.Markdown(f"### {current_section_title}")
|
344 |
+
|
345 |
+
with gr.Row(): # Create a new row for up to two plot panels
|
346 |
+
# First plot in the pair
|
347 |
+
config1 = plot_configs[i]
|
348 |
+
panel_col1, plot_component1, bomb_button1 = \
|
349 |
+
create_analytics_plot_panel(config1["label"], config1["id"])
|
350 |
+
plot_ui_objects[config1["id"]] = {
|
351 |
+
"plot_component": plot_component1,
|
352 |
+
"bomb_button": bomb_button1,
|
353 |
+
"label": config1["label"]
|
354 |
+
}
|
355 |
+
logging.debug(f"Created UI panel for plot_id: {config1['id']}")
|
356 |
+
|
357 |
+
# Second plot in the pair, if it exists
|
358 |
+
if i + 1 < len(plot_configs):
|
359 |
+
config2 = plot_configs[i+1]
|
360 |
+
# Check if the second plot starts a new section (edge case if sections aren't aligned with pairs)
|
361 |
+
if config2["section"] != current_section_title:
|
362 |
+
# This row is finished, start a new section header for the next plot
|
363 |
+
# This might leave the current row with only one plot if sections change mid-pair
|
364 |
+
# For simplicity, we assume sections align well or the header appears before the row with the new section's first plot
|
365 |
+
# The current loop structure will create a new header before the next gr.Row if section changes
|
366 |
+
pass # The next iteration's section check will handle this.
|
367 |
+
|
368 |
+
panel_col2, plot_component2, bomb_button2 = \
|
369 |
+
create_analytics_plot_panel(config2["label"], config2["id"])
|
370 |
+
plot_ui_objects[config2["id"]] = {
|
371 |
+
"plot_component": plot_component2,
|
372 |
+
"bomb_button": bomb_button2,
|
373 |
+
"label": config2["label"]
|
374 |
+
}
|
375 |
+
logging.debug(f"Created UI panel for plot_id: {config2['id']}")
|
376 |
+
else:
|
377 |
+
# If there's no second plot, this row will just have one panel
|
378 |
+
pass
|
379 |
|
380 |
+
logging.info(f"Finished building plot area. Total plot objects: {len(plot_ui_objects)}")
|
381 |
return plot_ui_objects
|