opti-alexc commited on
Commit
fc5823f
ยท
1 Parent(s): b0d3d02
Files changed (1) hide show
  1. app.py +31 -23
app.py CHANGED
@@ -14,7 +14,12 @@ BODY_ORDER = ['Very light-bodied', 'Light-bodied', 'Medium-bodied', 'Full-bodied
14
  ACIDITY_ORDER = ['Low', 'Medium', 'High']
15
  BODY_MAPPING = {'Very light-bodied': 1, 'Light-bodied': 2, 'Medium-bodied': 3, 'Full-bodied': 4, 'Very full-bodied': 5}
16
  WINE_TYPE_ORDER = {'Red': 2, 'Rosรฉ': 1, 'White': 0}
17
- SAMPLE_THRESHOLDS = {'Common (100+)': 100, 'Uncommon (50+)': 50, 'Rare (20+)': 20}
 
 
 
 
 
18
  COUNTRY_FLAGS = {
19
  'United States': '๐Ÿ‡บ๐Ÿ‡ธ', 'France': '๐Ÿ‡ซ๐Ÿ‡ท', 'Italy': '๐Ÿ‡ฎ๐Ÿ‡น', 'Spain': '๐Ÿ‡ช๐Ÿ‡ธ', 'Germany': '๐Ÿ‡ฉ๐Ÿ‡ช', 'Australia': '๐Ÿ‡ฆ๐Ÿ‡บ',
20
  'Chile': '๐Ÿ‡จ๐Ÿ‡ฑ', 'Argentina': '๐Ÿ‡ฆ๐Ÿ‡ท', 'Portugal': '๐Ÿ‡ต๐Ÿ‡น', 'South Africa': '๐Ÿ‡ฟ๐Ÿ‡ฆ', 'New Zealand': '๐Ÿ‡ณ๐Ÿ‡ฟ',
@@ -270,8 +275,8 @@ def create_wine_chart(chart_data, regional_grouping):
270
  fig = make_subplots(
271
  rows=1, cols=5,
272
  specs=[[{}, {"type": "bar"}, {"type": "bar"}, {"type": "box"}, {}]],
273
- column_widths=[0.30, 0.25, 0.25, 0.15, 0.05],
274
- horizontal_spacing=0.02,
275
  shared_yaxes=True
276
  )
277
 
@@ -293,7 +298,7 @@ def create_wine_chart(chart_data, regional_grouping):
293
  fig.add_trace(go.Scatter(
294
  y=y_labels, x=[0.03] * num_rows, mode='text',
295
  text=y_labels, textposition='middle right',
296
- textfont={'size': 14, 'color': '#2F2F2F'},
297
  hoverinfo='none', showlegend=False
298
  ), row=1, col=1)
299
 
@@ -350,7 +355,7 @@ def create_wine_chart(chart_data, regional_grouping):
350
  fig.add_trace(go.Scatter(
351
  y=y_labels, x=[0.5] * num_rows, mode='text',
352
  text=chart_data['pairing_emoji'], textposition='middle center',
353
- textfont={'size': 22}, showlegend=False,
354
  hoverinfo='text', hovertext=chart_data['pairing_names']
355
  ), row=1, col=5)
356
 
@@ -358,22 +363,22 @@ def create_wine_chart(chart_data, regional_grouping):
358
  title={
359
  'text': "Wine Characteristics by Grape Variety",
360
  'x': 0.5,
361
- 'font': {'size': 24, 'color': '#2F2F2F'}
362
  },
363
- height=max(500, num_rows * 40),
364
- barmode='stack', showlegend=False, plot_bgcolor='#FFFFFF', paper_bgcolor='#F5F5F5',
365
- margin=dict(l=10, r=10, t=120, b=20), boxgap=0.5, bargap=0.4
366
  )
367
 
368
- column_titles = ["Wine / Hover for Info", "Body Profile (%)", "Acidity Profile (%)", "Alcohol (ABV %)", "Food Pairing"]
369
  # Add column titles
370
  title_start = time.time()
371
  for i, title in enumerate(column_titles, 1):
372
  domain = fig.layout[f'xaxis{i if i > 1 else ""}'].domain
373
  fig.add_annotation(
374
- x=(domain[0] + domain[1]) / 2, y=1.05,
375
  xref="paper", yref="paper", text=f"<b>{title}</b>",
376
- xanchor='center', showarrow=False, font={'size': 14, 'color': '#2F2F2F'}
377
  )
378
  print(f"[TIMING] Column titles completed in {time.time() - title_start:.2f}s")
379
 
@@ -381,7 +386,12 @@ def create_wine_chart(chart_data, regional_grouping):
381
  axes_start = time.time()
382
  for i in range(1, 6):
383
  fig.update_yaxes(showticklabels=False, showgrid=False, zeroline=False, row=1, col=i)
384
- fig.update_xaxes(showticklabels=False, showgrid=False, zeroline=False, title_text="", row=1, col=i)
 
 
 
 
 
385
  print(f"[TIMING] Axes formatting completed in {time.time() - axes_start:.2f}s")
386
 
387
  # Final axis configuration
@@ -390,14 +400,12 @@ def create_wine_chart(chart_data, regional_grouping):
390
  row=1, col=1)
391
  print(f"[TIMING] Final axis configuration completed in {time.time() - final_axes_start:.2f}s")
392
 
393
- # Skip alternating row backgrounds for better performance
394
- # The rectangles were causing major slowdown (3+ seconds)
395
- # bg_start = time.time()
396
- # for i in range(num_rows):
397
- # if i % 2 == 1:
398
- # fig.add_hrect(y0=i - 0.5, y1=i + 0.5, fillcolor="#F0F0F0", layer="below", line_width=0, row=1, col="all")
399
- # print(f"[TIMING] Background rectangles completed in {time.time() - bg_start:.2f}s")
400
- print("[TIMING] Skipped background rectangles for performance")
401
 
402
  chart_time = time.time() - chart_start
403
  print(f"[TIMING] Chart creation completed in {chart_time:.2f}s")
@@ -446,8 +454,8 @@ def create_interface():
446
  info="1: Varietals, 5: All Blends"
447
  )
448
  min_samples_choice = gr.Radio(
449
- choices=list(SAMPLE_THRESHOLDS.keys()), value='Common (100+)',
450
- label="Minimum Sample Size"
451
  )
452
  regional_grouping = gr.Checkbox(
453
  value=True, label="Split By Country"
 
14
  ACIDITY_ORDER = ['Low', 'Medium', 'High']
15
  BODY_MAPPING = {'Very light-bodied': 1, 'Light-bodied': 2, 'Medium-bodied': 3, 'Full-bodied': 4, 'Very full-bodied': 5}
16
  WINE_TYPE_ORDER = {'Red': 2, 'Rosรฉ': 1, 'White': 0}
17
+ SAMPLE_THRESHOLDS = {
18
+ 'Very Common (250+)': 250,
19
+ 'Common (100+)': 100,
20
+ 'Uncommon (50+)': 50,
21
+ 'Rare (20+)': 20
22
+ }
23
  COUNTRY_FLAGS = {
24
  'United States': '๐Ÿ‡บ๐Ÿ‡ธ', 'France': '๐Ÿ‡ซ๐Ÿ‡ท', 'Italy': '๐Ÿ‡ฎ๐Ÿ‡น', 'Spain': '๐Ÿ‡ช๐Ÿ‡ธ', 'Germany': '๐Ÿ‡ฉ๐Ÿ‡ช', 'Australia': '๐Ÿ‡ฆ๐Ÿ‡บ',
25
  'Chile': '๐Ÿ‡จ๐Ÿ‡ฑ', 'Argentina': '๐Ÿ‡ฆ๐Ÿ‡ท', 'Portugal': '๐Ÿ‡ต๐Ÿ‡น', 'South Africa': '๐Ÿ‡ฟ๐Ÿ‡ฆ', 'New Zealand': '๐Ÿ‡ณ๐Ÿ‡ฟ',
 
275
  fig = make_subplots(
276
  rows=1, cols=5,
277
  specs=[[{}, {"type": "bar"}, {"type": "bar"}, {"type": "box"}, {}]],
278
+ column_widths=[0.25, 0.22, 0.22, 0.16, 0.05],
279
+ horizontal_spacing=0.025,
280
  shared_yaxes=True
281
  )
282
 
 
298
  fig.add_trace(go.Scatter(
299
  y=y_labels, x=[0.03] * num_rows, mode='text',
300
  text=y_labels, textposition='middle right',
301
+ textfont={'size': 22, 'color': '#1A1A1A'},
302
  hoverinfo='none', showlegend=False
303
  ), row=1, col=1)
304
 
 
355
  fig.add_trace(go.Scatter(
356
  y=y_labels, x=[0.5] * num_rows, mode='text',
357
  text=chart_data['pairing_emoji'], textposition='middle center',
358
+ textfont={'size': 32}, showlegend=False,
359
  hoverinfo='text', hovertext=chart_data['pairing_names']
360
  ), row=1, col=5)
361
 
 
363
  title={
364
  'text': "Wine Characteristics by Grape Variety",
365
  'x': 0.5,
366
+ 'font': {'size': 26, 'color': '#1A1A1A'}
367
  },
368
+ height=max(600, num_rows * 55),
369
+ barmode='stack', showlegend=False, plot_bgcolor='#FAFAFA', paper_bgcolor='#E8E9EA',
370
+ margin=dict(l=30, r=30, t=100, b=60), boxgap=0.3, bargap=0.2
371
  )
372
 
373
+ column_titles = ["Grape Variety", "Body Profile (%)", "Acidity Profile (%)", "Alcohol (ABV %)", "Food Pairing"]
374
  # Add column titles
375
  title_start = time.time()
376
  for i, title in enumerate(column_titles, 1):
377
  domain = fig.layout[f'xaxis{i if i > 1 else ""}'].domain
378
  fig.add_annotation(
379
+ x=(domain[0] + domain[1]) / 2, y=1.02,
380
  xref="paper", yref="paper", text=f"<b>{title}</b>",
381
+ xanchor='center', showarrow=False, font={'size': 20, 'color': '#1A1A1A'}
382
  )
383
  print(f"[TIMING] Column titles completed in {time.time() - title_start:.2f}s")
384
 
 
386
  axes_start = time.time()
387
  for i in range(1, 6):
388
  fig.update_yaxes(showticklabels=False, showgrid=False, zeroline=False, row=1, col=i)
389
+ # Show x-axis labels only for body, acidity, and ABV columns
390
+ if i in [2, 3, 4]:
391
+ fig.update_xaxes(showticklabels=True, showgrid=True, gridcolor='rgba(0,0,0,0.1)',
392
+ zeroline=False, title_text="", row=1, col=i)
393
+ else:
394
+ fig.update_xaxes(showticklabels=False, showgrid=False, zeroline=False, title_text="", row=1, col=i)
395
  print(f"[TIMING] Axes formatting completed in {time.time() - axes_start:.2f}s")
396
 
397
  # Final axis configuration
 
400
  row=1, col=1)
401
  print(f"[TIMING] Final axis configuration completed in {time.time() - final_axes_start:.2f}s")
402
 
403
+ # Add alternating row backgrounds for better readability
404
+ bg_start = time.time()
405
+ for i in range(num_rows):
406
+ if i % 2 == 1:
407
+ fig.add_hrect(y0=i - 0.5, y1=i + 0.5, fillcolor="#F0F2F3", layer="below", line_width=0, row=1, col="all")
408
+ print(f"[TIMING] Background rectangles completed in {time.time() - bg_start:.2f}s")
 
 
409
 
410
  chart_time = time.time() - chart_start
411
  print(f"[TIMING] Chart creation completed in {chart_time:.2f}s")
 
454
  info="1: Varietals, 5: All Blends"
455
  )
456
  min_samples_choice = gr.Radio(
457
+ choices=list(SAMPLE_THRESHOLDS.keys()), value='Very Common (250+)',
458
+ label="Minimum Sample Size (Wines per Variety)",
459
  )
460
  regional_grouping = gr.Checkbox(
461
  value=True, label="Split By Country"