2020-08-22 05:20:05 +08:00
|
|
|
# (Radio, CheckboxGroup, Slider, Dropdown) -> (Image)
|
|
|
|
|
2020-06-16 02:57:49 +08:00
|
|
|
import gradio as gr
|
|
|
|
import random
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
import numpy as np
|
|
|
|
|
2020-07-09 06:09:52 +08:00
|
|
|
|
2020-08-20 05:27:22 +08:00
|
|
|
def stock_forecast(final_year, companies, noise, show_legend, point_style):
|
2020-06-16 02:57:49 +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]
|
|
|
|
for i, company in enumerate(companies):
|
|
|
|
series = np.arange(0, year_count, dtype=float)
|
|
|
|
series = series ** 2 * (i + 1)
|
|
|
|
series += np.random.rand(year_count) * noise
|
|
|
|
plt.plot(x, series, plt_format)
|
|
|
|
if show_legend:
|
|
|
|
plt.legend(companies)
|
|
|
|
return plt
|
|
|
|
|
2020-07-09 06:09:52 +08:00
|
|
|
|
2020-08-20 05:27:22 +08:00
|
|
|
gr.Interface(stock_forecast,
|
2020-06-16 02:57:49 +08:00
|
|
|
[
|
|
|
|
gr.inputs.Radio([2025, 2030, 2035, 2040],
|
|
|
|
label="Project to:"),
|
|
|
|
gr.inputs.CheckboxGroup(
|
2020-08-20 05:27:22 +08:00
|
|
|
["Google", "Microsoft", "Gradio"]),
|
|
|
|
gr.inputs.Slider(1, 100),
|
|
|
|
"checkbox",
|
2020-06-16 02:57:49 +08:00
|
|
|
gr.inputs.Dropdown(["cross", "line", "circle"], label="Style"),
|
2020-06-19 04:15:27 +08:00
|
|
|
],
|
|
|
|
gr.outputs.Image(plot=True, label="forecast")
|
|
|
|
).launch()
|