|
import gradio as gr |
|
import plotly.graph_objects as go |
|
import pandas as pd |
|
|
|
|
|
big_five_capex: list[tuple[str, int, int, int, int, int]] = [ |
|
("2014 Q3", 1282, 2417, 482, 3826, 1378), |
|
("2014 Q4", 1490, 3606, 517, 3217, 1145), |
|
("2015 Q1", 1391, 2927, 502, 2369, 871), |
|
("2015 Q2", 1781, 2515, 549, 2043, 1213), |
|
("2015 Q3", 1356, 2406, 780, 3618, 1195), |
|
("2015 Q4", 2024, 2102, 692, 3612, 1309), |
|
("2016 Q1", 2308, 2444, 1132, 2336, 1179), |
|
("2016 Q2", 2655, 2136, 995, 2809, 1711), |
|
("2016 Q3", 2163, 2554, 1095, 3977, 1841), |
|
("2016 Q4", 1988, 3078, 1269, 3334, 3073), |
|
("2017 Q1", 1695, 2508, 1271, 2975, 2148), |
|
("2017 Q2", 2283, 2831, 1444, 2277, 3113), |
|
("2017 Q3", 2132, 3538, 1755, 3865, 3074), |
|
("2017 Q4", 2586, 4307, 2263, 2810, 3619), |
|
("2018 Q1", 2934, 7299, 2812, 4195, 3098), |
|
("2018 Q2", 3980, 5477, 3460, 3267, 3243), |
|
("2018 Q3", 3602, 5282, 3342, 3041, 3352), |
|
("2018 Q4", 3707, 7081, 4301, 3355, 3734), |
|
("2019 Q1", 2565, 4638, 3837, 2363, 3290), |
|
("2019 Q2", 4051, 6126, 3633, 2000, 3562), |
|
("2019 Q3", 3385, 6732, 3532, 2777, 4697), |
|
("2019 Q4", 3545, 6052, 4100, 2107, 5312), |
|
("2020 Q1", 3767, 6005, 3558, 1853, 6795), |
|
("2020 Q2", 4744, 5391, 3255, 1565, 7459), |
|
("2020 Q3", 4907, 5406, 3689, 1784, 11063), |
|
("2020 Q4", 4174, 5479, 4613, 3500, 14823), |
|
("2021 Q1", 5089, 5942, 4303, 2269, 12082), |
|
("2021 Q2", 6452, 5496, 4641, 2093, 14288), |
|
("2021 Q3", 5810, 6819, 4346, 3223, 15748), |
|
("2021 Q4", 5865, 6383, 5400, 2803, 18935), |
|
("2022 Q1", 5340, 9786, 5441, 2514, 14951), |
|
("2022 Q2", 6871, 6828, 7572, 2102, 15724), |
|
("2022 Q3", 6283, 7276, 9375, 3289, 16378), |
|
("2022 Q4", 6274, 7595, 9043, 3787, 16592), |
|
("2023 Q1", 6607, 6289, 6823, 2916, 14207), |
|
("2023 Q2", 8943, 6888, 6134, 2093, 11455), |
|
("2023 Q3", 9917, 8055, 6543, 2163, 12479), |
|
("2023 Q4", 9735, 11019, 7665, 2392, 14588), |
|
("2024 Q1", 10952, 12012, 6400, 1996, 14925), |
|
("2024 Q2", 13873, 13186, 8173, 2151, 17620), |
|
] |
|
|
|
|
|
def create_chart(): |
|
df = pd.DataFrame(big_five_capex, columns=['Quarter', 'Microsoft', 'Google', 'Meta', 'Apple', 'Amazon']) |
|
|
|
fig = go.Figure() |
|
|
|
companies = ['Microsoft', 'Google', 'Meta', 'Apple', 'Amazon'] |
|
colors = ['#80bb00', '#ee161f', '#0065e3', '#000000', '#ff6200'] |
|
|
|
for company, color in zip(companies, colors): |
|
fig.add_trace(go.Bar( |
|
x=df['Quarter'], |
|
y=df[company], |
|
name=company, |
|
marker_color=color |
|
)) |
|
|
|
fig.update_layout( |
|
title='Capital Expenditure of the Big Five Tech Companies in Millions of USD per Quarter', |
|
xaxis_title='Quarter', |
|
yaxis_title='Capex (Millions of USD)', |
|
barmode='stack', |
|
legend_title='Companies', |
|
height=800 |
|
) |
|
|
|
return fig |
|
|
|
|
|
with gr.Blocks() as demo: |
|
with gr.Tab("Big Five Capex"): |
|
big_five_capex_plot: gr.Plot = gr.Plot() |
|
generate_btn = gr.Button("Generate Plot") |
|
generate_btn.click(fn=create_chart, outputs=big_five_capex_plot) |
|
|
|
|
|
if __name__ == "__main__": |
|
demo.launch() |