Kaushik Rajan commited on
Commit
4887fce
·
1 Parent(s): f1fc436

Restore original plotting logic: return None for empty plots (fixes plotting functionality)

Browse files
Files changed (1) hide show
  1. app.py +19 -41
app.py CHANGED
@@ -347,48 +347,26 @@ def create_interface():
347
  analysis_box = gr.Textbox("", label="Strategy Insights", lines=5, interactive=False)
348
 
349
  def create_plots(history):
350
- try:
351
- df = pd.DataFrame(history)
352
-
353
- # Create empty figures if no data
354
- if df.empty:
355
- # Create empty plot with proper structure
356
- empty_fig_ms = px.line(title="Market Share (%)")
357
- empty_fig_ms.update_layout(yaxis_range=[0,100], legend_title_text='',
358
- xaxis_title="Quarter", yaxis_title="Market Share (%)")
359
-
360
- empty_fig_b = px.line(title="Budget ($)")
361
- empty_fig_b.update_layout(legend_title_text='',
362
- xaxis_title="Quarter", yaxis_title="Budget ($)")
363
-
364
- empty_fig_q = px.line(title="Product Quality Index")
365
- empty_fig_q.update_layout(legend_title_text='',
366
- xaxis_title="Quarter", yaxis_title="Quality Index")
367
-
368
- return empty_fig_ms, empty_fig_b, empty_fig_q
369
-
370
- fig_ms = px.line(df, x="Quarter", y=["Player Market Share", "AI Market Share"],
371
- title="Market Share (%)", markers=True,
372
- color_discrete_map={"Player Market Share": "#3b82f6", "AI Market Share": "#ef4444"})
373
- fig_ms.update_layout(yaxis_range=[0,100], legend_title_text='')
374
-
375
- fig_b = px.line(df, x="Quarter", y=["Player Budget", "AI Budget"],
376
- title="Budget ($)", markers=True,
377
- color_discrete_map={"Player Budget": "#3b82f6", "AI Budget": "#ef4444"})
378
- fig_b.update_layout(legend_title_text='')
379
-
380
- fig_q = px.line(df, x="Quarter", y=["Player Product Quality", "AI Product Quality"],
381
- title="Product Quality Index", markers=True,
382
- color_discrete_map={"Player Product Quality": "#3b82f6", "AI Product Quality": "#ef4444"})
383
- fig_q.update_layout(legend_title_text='')
384
-
385
- return fig_ms, fig_b, fig_q
386
 
387
- except Exception as e:
388
- print(f"Error creating plots: {e}")
389
- # Return empty figures as fallback
390
- empty_fig = px.line(title="Error loading chart")
391
- return empty_fig, empty_fig, empty_fig
 
 
 
 
 
 
 
 
 
 
 
392
 
393
  @spaces.GPU
394
  def game_step_and_update(env, mode, rd_raw, mkt_raw, sales_raw, rd_pct, mkt_pct, sales_pct):
 
347
  analysis_box = gr.Textbox("", label="Strategy Insights", lines=5, interactive=False)
348
 
349
  def create_plots(history):
350
+ df = pd.DataFrame(history)
351
+ if df.empty:
352
+ return None, None, None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
353
 
354
+ fig_ms = px.line(df, x="Quarter", y=["Player Market Share", "AI Market Share"],
355
+ title="Market Share (%)", markers=True,
356
+ color_discrete_map={"Player Market Share": "#3b82f6", "AI Market Share": "#ef4444"})
357
+ fig_ms.update_layout(yaxis_range=[0,100], legend_title_text='')
358
+
359
+ fig_b = px.line(df, x="Quarter", y=["Player Budget", "AI Budget"],
360
+ title="Budget ($)", markers=True,
361
+ color_discrete_map={"Player Budget": "#3b82f6", "AI Budget": "#ef4444"})
362
+ fig_b.update_layout(legend_title_text='')
363
+
364
+ fig_q = px.line(df, x="Quarter", y=["Player Product Quality", "AI Product Quality"],
365
+ title="Product Quality Index", markers=True,
366
+ color_discrete_map={"Player Product Quality": "#3b82f6", "AI Product Quality": "#ef4444"})
367
+ fig_q.update_layout(legend_title_text='')
368
+
369
+ return fig_ms, fig_b, fig_q
370
 
371
  @spaces.GPU
372
  def game_step_and_update(env, mode, rd_raw, mkt_raw, sales_raw, rd_pct, mkt_pct, sales_pct):