rhui96 commited on
Commit
ccf1990
ยท
verified ยท
1 Parent(s): 0583b3c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -77
app.py CHANGED
@@ -80,7 +80,6 @@ import gradio as gr
80
  # Authentication token for HuggingFace API access
81
  # Set via environment variable: export HF_TOKEN="your_token_here"
82
  HF_TOKEN = os.getenv("HF_TOKEN", "")
83
-
84
  # =================================================================================================
85
  # UI STYLING
86
  # =================================================================================================
@@ -1565,14 +1564,14 @@ def process_request(
1565
  output_tokens: float,
1566
  dataset_tier: str,
1567
  manufacturers: list[str],
1568
- ) -> Tuple[str, str, str, Any, Any, Any]: #, Any]:
1569
  """
1570
  Main request processing function.
1571
 
1572
  Orchestrates model resolution, VRAM calculation, and hardware recommendation.
1573
 
1574
  Returns:
1575
- Tuple of (report, budget_rec, runner_up_rec, throughput_chart, cost_chart, vram_chart, efficiency_chart)
1576
  """
1577
  try:
1578
  # Validate inputs
@@ -1630,7 +1629,7 @@ def process_request(
1630
  )
1631
 
1632
  if error:
1633
- return error, "", "", None, None, None, None
1634
 
1635
  # Generate report
1636
  report = f"""
@@ -1661,84 +1660,63 @@ def process_request(
1661
  *โ„น๏ธ NOTE: VRAM estimates include 10% safety buffer. Actual usage may vary ยฑ15-20% based on framework optimizations, model architecture details, and runtime conditions. Throughput estimates are based on empirical benchmarks and may vary in production.*
1662
  """
1663
 
1664
- # Create bar charts using Plotly
1665
- throughput_chart = None
1666
- cost_chart = None
1667
- vram_chart = None
1668
- efficiency_chart = None
1669
 
1670
  if chart_data and chart_data.get("names"):
1671
  import plotly.graph_objects as go
1672
 
1673
- # Throughput chart
1674
- throughput_chart = go.Figure(data=[
 
 
 
 
 
 
1675
  go.Bar(
 
1676
  x=chart_data["names"],
1677
- y=chart_data["throughput"],
1678
- marker_color='#22c55e'
1679
- )
1680
- ])
1681
- throughput_chart.update_layout(
1682
- title="Throughput Comparison",
1683
- xaxis_title="GPU Configuration",
1684
- yaxis_title="Tokens/sec",
1685
- height=350,
1686
- xaxis_tickangle=-45,
1687
- margin=dict(b=120)
1688
- )
1689
-
1690
- # Cost chart
1691
- cost_chart = go.Figure(data=[
1692
  go.Bar(
 
1693
  x=chart_data["names"],
1694
- y=chart_data["cost"],
1695
- marker_color='#3b82f6'
1696
- )
1697
- ])
1698
- cost_chart.update_layout(
1699
- title="Cost Comparison",
1700
- xaxis_title="GPU Configuration",
1701
- yaxis_title="โ‚น/hour",
1702
- height=350,
1703
- xaxis_tickangle=-45,
1704
- margin=dict(b=120)
1705
- )
1706
-
1707
- # VRAM utilization chart
1708
- vram_chart = go.Figure(data=[
1709
  go.Bar(
 
1710
  x=chart_data["names"],
1711
  y=chart_data["vram_util"],
1712
- marker_color='#a855f7'
 
1713
  )
1714
  ])
1715
- vram_chart.update_layout(
1716
- title="VRAM Utilization Comparison",
 
1717
  xaxis_title="GPU Configuration",
1718
- yaxis_title="Utilization %",
1719
- height=350,
 
1720
  xaxis_tickangle=-45,
1721
- margin=dict(b=120)
1722
- )
1723
-
1724
- # Cost efficiency chart
1725
- efficiency_chart = go.Figure(data=[
1726
- go.Bar(
1727
- x=chart_data["names"],
1728
- y=chart_data["cost_efficiency"],
1729
- marker_color='#f59e0b'
1730
  )
1731
- ])
1732
- # efficiency_chart.update_layout(
1733
- # title="Cost Efficiency Comparison",
1734
- # xaxis_title="GPU Configuration",
1735
- # yaxis_title="Throughput / Cost",
1736
- # height=350,
1737
- # xaxis_tickangle=-45,
1738
- # margin=dict(b=120)
1739
- # )
1740
 
1741
- return report, budget_rec, runner_up_rec, throughput_chart, cost_chart, vram_chart #, efficiency_chart
1742
 
1743
  except Exception as e:
1744
  error_msg = f"""
@@ -1747,7 +1725,7 @@ def process_request(
1747
  <p>{str(e)}</p>
1748
  </div>
1749
  """
1750
- return error_msg, "", "", None, None, None, None
1751
 
1752
  # =================================================================================================
1753
  # UI Event Handlers
@@ -1909,17 +1887,9 @@ def create_interface() -> gr.Blocks:
1909
  with gr.Column(elem_classes=["runner-box"]):
1910
  rec_out_2 = gr.Markdown()
1911
 
1912
- # Bar chart comparison section with tabs inside Accordion
1913
  with gr.Accordion("๐Ÿ“Š GPU Comparison (Top 10 by Cost)", open=False):
1914
- with gr.Tabs():
1915
- with gr.Tab("Cost"):
1916
- cost_plot = gr.Plot(label="Cost Comparison")
1917
- with gr.Tab("Throughput"):
1918
- throughput_plot = gr.Plot(label="Throughput Comparison")
1919
- with gr.Tab("VRAM Utilization"):
1920
- vram_plot = gr.Plot(label="VRAM Utilization Comparison")
1921
- # with gr.Tab("Cost Efficiency"):
1922
- # efficiency_plot = gr.Plot(label="Cost Efficiency Comparison")
1923
 
1924
  with gr.Accordion("๐Ÿ“ˆ Details", open=False):
1925
  report_out = gr.Markdown()
@@ -1955,7 +1925,7 @@ def create_interface() -> gr.Blocks:
1955
  ft_method, rank, batch, sample_count,
1956
  input_tokens, output_tokens, dataset_tier, manufacturers,
1957
  ],
1958
- outputs=[report_out, rec_out_1, rec_out_2, throughput_plot, cost_plot, vram_plot] #, efficiency_plot]
1959
  )
1960
 
1961
  return demo
 
80
  # Authentication token for HuggingFace API access
81
  # Set via environment variable: export HF_TOKEN="your_token_here"
82
  HF_TOKEN = os.getenv("HF_TOKEN", "")
 
83
  # =================================================================================================
84
  # UI STYLING
85
  # =================================================================================================
 
1564
  output_tokens: float,
1565
  dataset_tier: str,
1566
  manufacturers: list[str],
1567
+ ) -> Tuple[str, str, str, Any]:
1568
  """
1569
  Main request processing function.
1570
 
1571
  Orchestrates model resolution, VRAM calculation, and hardware recommendation.
1572
 
1573
  Returns:
1574
+ Tuple of (report, budget_rec, runner_up_rec, combined_chart)
1575
  """
1576
  try:
1577
  # Validate inputs
 
1629
  )
1630
 
1631
  if error:
1632
+ return error, "", "", None
1633
 
1634
  # Generate report
1635
  report = f"""
 
1660
  *โ„น๏ธ NOTE: VRAM estimates include 10% safety buffer. Actual usage may vary ยฑ15-20% based on framework optimizations, model architecture details, and runtime conditions. Throughput estimates are based on empirical benchmarks and may vary in production.*
1661
  """
1662
 
1663
+ # Create grouped multi-bar chart using Plotly
1664
+ combined_chart = None
 
 
 
1665
 
1666
  if chart_data and chart_data.get("names"):
1667
  import plotly.graph_objects as go
1668
 
1669
+ # Normalize values to percentages for comparison (0-100 scale)
1670
+ max_throughput = max(chart_data["throughput"]) if chart_data["throughput"] else 1
1671
+ max_cost = max(chart_data["cost"]) if chart_data["cost"] else 1
1672
+
1673
+ throughput_normalized = [(t / max_throughput) * 100 for t in chart_data["throughput"]]
1674
+ cost_normalized = [(c / max_cost) * 100 for c in chart_data["cost"]]
1675
+
1676
+ combined_chart = go.Figure(data=[
1677
  go.Bar(
1678
+ name='Throughput',
1679
  x=chart_data["names"],
1680
+ y=throughput_normalized,
1681
+ marker_color='#22c55e',
1682
+ hovertemplate='%{x}<br>Throughput: %{customdata:,.0f} tok/s<extra></extra>',
1683
+ customdata=chart_data["throughput"]
1684
+ ),
 
 
 
 
 
 
 
 
 
 
1685
  go.Bar(
1686
+ name='Cost',
1687
  x=chart_data["names"],
1688
+ y=cost_normalized,
1689
+ marker_color='#3b82f6',
1690
+ hovertemplate='%{x}<br>Cost: โ‚น%{customdata:,.2f}/hr<extra></extra>',
1691
+ customdata=chart_data["cost"]
1692
+ ),
 
 
 
 
 
 
 
 
 
 
1693
  go.Bar(
1694
+ name='VRAM Utilization',
1695
  x=chart_data["names"],
1696
  y=chart_data["vram_util"],
1697
+ marker_color='#a855f7',
1698
+ hovertemplate='%{x}<br>VRAM Util: %{y:.1f}%<extra></extra>'
1699
  )
1700
  ])
1701
+
1702
+ combined_chart.update_layout(
1703
+ title_text="GPU Comparison (Top 10 by Cost)",
1704
  xaxis_title="GPU Configuration",
1705
+ yaxis_title="Normalized Value (% of max)",
1706
+ barmode='group',
1707
+ height=450,
1708
  xaxis_tickangle=-45,
1709
+ margin=dict(b=120),
1710
+ legend=dict(
1711
+ orientation="h",
1712
+ yanchor="bottom",
1713
+ y=1.02,
1714
+ xanchor="center",
1715
+ x=0.5
 
 
1716
  )
1717
+ )
 
 
 
 
 
 
 
 
1718
 
1719
+ return report, budget_rec, runner_up_rec, combined_chart
1720
 
1721
  except Exception as e:
1722
  error_msg = f"""
 
1725
  <p>{str(e)}</p>
1726
  </div>
1727
  """
1728
+ return error_msg, "", "", None
1729
 
1730
  # =================================================================================================
1731
  # UI Event Handlers
 
1887
  with gr.Column(elem_classes=["runner-box"]):
1888
  rec_out_2 = gr.Markdown()
1889
 
1890
+ # Bar chart comparison section
1891
  with gr.Accordion("๐Ÿ“Š GPU Comparison (Top 10 by Cost)", open=False):
1892
+ combined_plot = gr.Plot(label="GPU Comparison")
 
 
 
 
 
 
 
 
1893
 
1894
  with gr.Accordion("๐Ÿ“ˆ Details", open=False):
1895
  report_out = gr.Markdown()
 
1925
  ft_method, rank, batch, sample_count,
1926
  input_tokens, output_tokens, dataset_tier, manufacturers,
1927
  ],
1928
+ outputs=[report_out, rec_out_1, rec_out_2, combined_plot]
1929
  )
1930
 
1931
  return demo