2021-05-24 23:31:44 +08:00
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
import gradio as gr
|
2022-01-21 21:44:12 +08:00
|
|
|
|
2022-05-14 13:45:44 +08:00
|
|
|
def plot_forecast(final_year, companies, noise, show_legend, point_style):
|
2021-05-24 23:31:44 +08:00
|
|
|
start_year = 2020
|
|
|
|
x = np.arange(start_year, final_year + 1)
|
|
|
|
year_count = x.shape[0]
|
|
|
|
plt_format = ({"cross": "X", "line": "-", "circle": "o--"})[point_style]
|
|
|
|
fig = plt.figure()
|
|
|
|
ax = fig.add_subplot(111)
|
|
|
|
for i, company in enumerate(companies):
|
|
|
|
series = np.arange(0, year_count, dtype=float)
|
2022-02-09 02:56:13 +08:00
|
|
|
series = series**2 * (i + 1)
|
2021-05-24 23:31:44 +08:00
|
|
|
series += np.random.rand(year_count) * noise
|
|
|
|
ax.plot(x, series, plt_format)
|
|
|
|
if show_legend:
|
|
|
|
plt.legend(companies)
|
|
|
|
return fig
|
|
|
|
|
2022-03-29 06:28:01 +08:00
|
|
|
demo = gr.Interface(
|
2022-05-14 13:45:44 +08:00
|
|
|
plot_forecast,
|
2021-05-24 23:31:44 +08:00
|
|
|
[
|
2022-03-29 06:28:01 +08:00
|
|
|
gr.Radio([2025, 2030, 2035, 2040], label="Project to:"),
|
2022-05-14 13:45:44 +08:00
|
|
|
gr.CheckboxGroup(["Google", "Microsoft", "Gradio"], label="Company Selection"),
|
2022-05-16 14:55:35 +08:00
|
|
|
gr.Slider(1, 100, label="Noise Level"),
|
2022-05-14 13:45:44 +08:00
|
|
|
gr.Checkbox(label="Show Legend"),
|
2022-03-29 06:28:01 +08:00
|
|
|
gr.Dropdown(["cross", "line", "circle"], label="Style"),
|
2021-05-24 23:31:44 +08:00
|
|
|
],
|
2024-07-13 07:56:25 +08:00
|
|
|
gr.Plot(label="forecast", format="png"),
|
2021-05-24 23:31:44 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2022-03-29 06:28:01 +08:00
|
|
|
demo.launch()
|