Spaces:
Sleeping
Sleeping
gauravlochab
commited on
Commit
·
31508e9
1
Parent(s):
4635a36
refactor: streamline APR visualization generation and update graph handling
Browse files
app.py
CHANGED
|
@@ -214,30 +214,24 @@ def generate_apr_visualizations():
|
|
| 214 |
yaxis=dict(showgrid=False, zeroline=False, showticklabels=False)
|
| 215 |
)
|
| 216 |
|
| 217 |
-
# Save as static
|
| 218 |
-
fig.write_html("modius_apr_per_agent_graph.html")
|
| 219 |
-
fig.write_image("modius_apr_per_agent_graph.png")
|
| 220 |
fig.write_html("modius_apr_combined_graph.html")
|
| 221 |
fig.write_image("modius_apr_combined_graph.png")
|
| 222 |
|
| 223 |
csv_file = None
|
| 224 |
-
return fig,
|
| 225 |
|
| 226 |
# No longer generating dummy data
|
| 227 |
# Set global_df for access by other functions
|
| 228 |
global_df = df
|
| 229 |
-
|
| 230 |
-
print(df.head())
|
| 231 |
# Save to CSV before creating visualizations
|
| 232 |
csv_file = save_to_csv(df)
|
| 233 |
|
| 234 |
-
#
|
| 235 |
-
per_agent_fig = create_time_series_graph_per_agent(df)
|
| 236 |
-
|
| 237 |
-
# Create combined time series graph (returns figure object)
|
| 238 |
combined_fig = create_combined_time_series_graph(df)
|
| 239 |
|
| 240 |
-
return
|
| 241 |
|
| 242 |
def create_time_series_graph_per_agent(df):
|
| 243 |
"""Create a time series graph for each agent using Plotly"""
|
|
@@ -939,34 +933,32 @@ def dashboard():
|
|
| 939 |
with gr.Column():
|
| 940 |
refresh_btn = gr.Button("Refresh APR Data")
|
| 941 |
|
| 942 |
-
# Create
|
| 943 |
-
|
| 944 |
-
combined_graph = gr.Plot(label="Combined APR (All Agents)")
|
| 945 |
|
| 946 |
-
# Function to update
|
| 947 |
-
def
|
| 948 |
-
# Generate
|
| 949 |
-
|
| 950 |
-
return
|
| 951 |
|
| 952 |
# Set up the button click event
|
| 953 |
refresh_btn.click(
|
| 954 |
-
fn=
|
| 955 |
inputs=[],
|
| 956 |
-
outputs=[
|
| 957 |
)
|
| 958 |
|
| 959 |
-
# Initialize the
|
| 960 |
-
# We'll use placeholder
|
| 961 |
import plotly.graph_objects as go
|
| 962 |
placeholder_fig = go.Figure()
|
| 963 |
placeholder_fig.add_annotation(
|
| 964 |
-
text="Click 'Refresh APR Data' to load APR
|
| 965 |
x=0.5, y=0.5,
|
| 966 |
showarrow=False,
|
| 967 |
font=dict(size=15)
|
| 968 |
)
|
| 969 |
-
per_agent_graph.value = placeholder_fig
|
| 970 |
combined_graph.value = placeholder_fig
|
| 971 |
|
| 972 |
return demo
|
|
|
|
| 214 |
yaxis=dict(showgrid=False, zeroline=False, showticklabels=False)
|
| 215 |
)
|
| 216 |
|
| 217 |
+
# Save as static file for reference
|
|
|
|
|
|
|
| 218 |
fig.write_html("modius_apr_combined_graph.html")
|
| 219 |
fig.write_image("modius_apr_combined_graph.png")
|
| 220 |
|
| 221 |
csv_file = None
|
| 222 |
+
return fig, csv_file
|
| 223 |
|
| 224 |
# No longer generating dummy data
|
| 225 |
# Set global_df for access by other functions
|
| 226 |
global_df = df
|
| 227 |
+
|
|
|
|
| 228 |
# Save to CSV before creating visualizations
|
| 229 |
csv_file = save_to_csv(df)
|
| 230 |
|
| 231 |
+
# Only create combined time series graph
|
|
|
|
|
|
|
|
|
|
| 232 |
combined_fig = create_combined_time_series_graph(df)
|
| 233 |
|
| 234 |
+
return combined_fig, csv_file
|
| 235 |
|
| 236 |
def create_time_series_graph_per_agent(df):
|
| 237 |
"""Create a time series graph for each agent using Plotly"""
|
|
|
|
| 933 |
with gr.Column():
|
| 934 |
refresh_btn = gr.Button("Refresh APR Data")
|
| 935 |
|
| 936 |
+
# Create container for plotly figure (combined graph only)
|
| 937 |
+
combined_graph = gr.Plot(label="APR for All Agents")
|
|
|
|
| 938 |
|
| 939 |
+
# Function to update the graph
|
| 940 |
+
def update_apr_graph():
|
| 941 |
+
# Generate visualization and get figure object directly
|
| 942 |
+
combined_fig, _ = generate_apr_visualizations()
|
| 943 |
+
return combined_fig
|
| 944 |
|
| 945 |
# Set up the button click event
|
| 946 |
refresh_btn.click(
|
| 947 |
+
fn=update_apr_graph,
|
| 948 |
inputs=[],
|
| 949 |
+
outputs=[combined_graph]
|
| 950 |
)
|
| 951 |
|
| 952 |
+
# Initialize the graph on load
|
| 953 |
+
# We'll use placeholder figure initially
|
| 954 |
import plotly.graph_objects as go
|
| 955 |
placeholder_fig = go.Figure()
|
| 956 |
placeholder_fig.add_annotation(
|
| 957 |
+
text="Click 'Refresh APR Data' to load APR graph",
|
| 958 |
x=0.5, y=0.5,
|
| 959 |
showarrow=False,
|
| 960 |
font=dict(size=15)
|
| 961 |
)
|
|
|
|
| 962 |
combined_graph.value = placeholder_fig
|
| 963 |
|
| 964 |
return demo
|