delightfulrachel commited on
Commit
46a2215
·
verified ·
1 Parent(s): 229a3d1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -5
app.py CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
2
  import pandas as pd
3
  import numpy as np
4
  import plotly.express as px
 
5
 
6
  # Pricing data
7
  aws_instances = {
@@ -154,12 +155,41 @@ def generate_cost_comparison(
154
 
155
  # Recommendation and Breakeven omitted for brevity
156
 
157
- # Chart
158
  df = pd.DataFrame(results)
159
  colors = {r['provider']: c for r,c in zip(results, ['#FF9900','#4285F4','#D62828'])}
160
- fig = px.bar(df, x='provider', y='cost', color='provider', color_discrete_map=colors)
161
- fig.update_yaxes(tickprefix='$')
162
- fig.update_layout(showlegend=False, height=500)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
 
164
  html = f"""
165
  <div style='padding:20px;font-family:Arial;'>
@@ -193,4 +223,4 @@ with gr.Blocks(title="Cloud Cost Estimator", theme=gr.themes.Soft(primary_hue="i
193
  model_size, storage_gb, reserved_instances, spot_instances, multi_year_commitment],
194
  outputs=[out_html, out_plot])
195
 
196
- demo.launch()
 
2
  import pandas as pd
3
  import numpy as np
4
  import plotly.express as px
5
+ import plotly.graph_objects as go
6
 
7
  # Pricing data
8
  aws_instances = {
 
155
 
156
  # Recommendation and Breakeven omitted for brevity
157
 
158
+ # Chart with annotations
159
  df = pd.DataFrame(results)
160
  colors = {r['provider']: c for r,c in zip(results, ['#FF9900','#4285F4','#D62828'])}
161
+
162
+ # Create figure using plotly graph objects for more control
163
+ fig = go.Figure()
164
+
165
+ # Add bars
166
+ for i, row in df.iterrows():
167
+ fig.add_trace(go.Bar(
168
+ x=[row['provider']],
169
+ y=[row['cost']],
170
+ name=row['provider'],
171
+ marker_color=colors[row['provider']]
172
+ ))
173
+
174
+ # Add annotations on top of each bar
175
+ for i, row in df.iterrows():
176
+ fig.add_annotation(
177
+ x=row['provider'],
178
+ y=row['cost'],
179
+ text=f"${row['cost']:.2f}",
180
+ showarrow=False,
181
+ yshift=10, # Position above the bar
182
+ font=dict(size=14)
183
+ )
184
+
185
+ # Update layout
186
+ fig.update_layout(
187
+ showlegend=False,
188
+ height=500,
189
+ yaxis=dict(title='Monthly Cost ($)', tickprefix='$'),
190
+ xaxis=dict(title=''),
191
+ title='Cost Comparison'
192
+ )
193
 
194
  html = f"""
195
  <div style='padding:20px;font-family:Arial;'>
 
223
  model_size, storage_gb, reserved_instances, spot_instances, multi_year_commitment],
224
  outputs=[out_html, out_plot])
225
 
226
+ demo.launch()