Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import matplotlib.pyplot as plt
|
| 2 |
+
import numpy as np
|
| 3 |
+
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
def plot_forecast(final_year, companies, noise, show_legend, point_style):
|
| 7 |
+
start_year = 2020
|
| 8 |
+
x = np.arange(start_year, final_year + 1)
|
| 9 |
+
year_count = x.shape[0]
|
| 10 |
+
plt_format = ({"cross": "X", "line": "-", "circle": "o--"})[point_style]
|
| 11 |
+
fig = plt.figure()
|
| 12 |
+
ax = fig.add_subplot(111)
|
| 13 |
+
for i, company in enumerate(companies):
|
| 14 |
+
series = np.arange(0, year_count, dtype=float)
|
| 15 |
+
series = series**2 * (i + 1)
|
| 16 |
+
series += np.random.rand(year_count) * noise
|
| 17 |
+
ax.plot(x, series, plt_format)
|
| 18 |
+
if show_legend:
|
| 19 |
+
plt.legend(companies)
|
| 20 |
+
return fig
|
| 21 |
+
|
| 22 |
+
demo = gr.Interface(
|
| 23 |
+
plot_forecast,
|
| 24 |
+
[
|
| 25 |
+
gr.Radio([2025, 2030, 2035, 2040], label="Project to:"),
|
| 26 |
+
gr.CheckboxGroup(["Google", "Microsoft", "Gradio"], label="Company Selection"),
|
| 27 |
+
gr.Slider(1, 100, label="Noise Level"),
|
| 28 |
+
gr.Checkbox(label="Show Legend"),
|
| 29 |
+
gr.Dropdown(["cross", "line", "circle"], label="Style"),
|
| 30 |
+
],
|
| 31 |
+
gr.Plot(label="forecast", format="png"),
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
if __name__ == "__main__":
|
| 35 |
+
demo.launch()
|