S-Dreamer commited on
Commit
6d9bc02
·
verified ·
1 Parent(s): a797ded

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -9
app.py CHANGED
@@ -2,33 +2,49 @@ import matplotlib.pyplot as plt
2
  import numpy as np
3
  import gradio as gr
4
 
5
- def plot_forecast(final_year, cryptocurrencies, noise, show_legend, point_style):
6
  start_year = 2020
7
  x = np.arange(start_year, final_year + 1)
8
  year_count = x.shape[0]
9
  plt_format = ({"cross": "X", "line": "-", "circle": "o--"})[point_style]
 
10
  fig = plt.figure()
11
  ax = fig.add_subplot(111)
 
12
  for i, crypto in enumerate(cryptocurrencies):
13
  series = np.arange(0, year_count, dtype=float)
14
  series = series**2 * (i + 1)
15
  series += np.random.rand(year_count) * noise
16
- ax.plot(x, series, plt_format, label=crypto)
 
17
  if show_legend:
18
  plt.legend()
 
 
 
 
 
19
  return fig
20
 
 
 
 
 
21
  demo = gr.Interface(
22
  plot_forecast,
23
  [
24
- gr.Radio([2025, 2030, 2035, 2040], label="Project to:"),
25
- gr.CheckboxGroup(["Bitcoin", "Ethereum", "Litecoin"], label="Cryptocurrency Selection"),
26
- gr.Slider(1, 100, label="Noise Level"),
27
- gr.Checkbox(label="Show Legend"),
28
- gr.Dropdown(["cross", "line", "circle"], label="Style"),
 
29
  ],
30
- gr.Plot(label="forecast", format="png"),
 
 
 
31
  )
32
 
33
  if __name__ == "__main__":
34
- demo.launch(show_error=True)
 
2
  import numpy as np
3
  import gradio as gr
4
 
5
+ def plot_forecast(final_year, cryptocurrencies, noise, show_legend, point_style, line_colors):
6
  start_year = 2020
7
  x = np.arange(start_year, final_year + 1)
8
  year_count = x.shape[0]
9
  plt_format = ({"cross": "X", "line": "-", "circle": "o--"})[point_style]
10
+
11
  fig = plt.figure()
12
  ax = fig.add_subplot(111)
13
+
14
  for i, crypto in enumerate(cryptocurrencies):
15
  series = np.arange(0, year_count, dtype=float)
16
  series = series**2 * (i + 1)
17
  series += np.random.rand(year_count) * noise
18
+ ax.plot(x, series, plt_format, label=crypto, color=line_colors[i % len(line_colors)])
19
+
20
  if show_legend:
21
  plt.legend()
22
+
23
+ ax.set_xlabel("Year")
24
+ ax.set_ylabel("Value")
25
+ ax.set_title(f"Cryptocurrency Forecast from {start_year} to {final_year}")
26
+
27
  return fig
28
 
29
+ # Create a color palette for the plot
30
+ def generate_color_palette():
31
+ return ["#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#9467bd"]
32
+
33
  demo = gr.Interface(
34
  plot_forecast,
35
  [
36
+ gr.Radio([2025, 2030, 2035, 2040], label="Project to:", info="Select the forecast year."),
37
+ gr.CheckboxGroup(["Bitcoin", "Ethereum", "Litecoin"], label="Cryptocurrency Selection", info="Choose which cryptocurrencies to forecast."),
38
+ gr.Slider(1, 100, label="Noise Level", info="Adjust the level of random noise added to the data."),
39
+ gr.Checkbox(label="Show Legend", info="Toggle the display of the legend."),
40
+ gr.Dropdown(["cross", "line", "circle"], label="Point Style", info="Choose the marker style for the plot."),
41
+ gr.ColorPicker(label="Line Colors", value="#1f77b4", info="Choose line colors for the plot.", show_alpha=False), # Color picker for lines
42
  ],
43
+ outputs=gr.Plot(label="Forecast Plot", format="png"),
44
+ layout="vertical", # Improved layout for better organization
45
+ title="Cryptocurrency Forecasting Tool", # Added title
46
+ theme="huggingface", # Applying a predefined theme for better look and feel
47
  )
48
 
49
  if __name__ == "__main__":
50
+ demo.launch(show_error=True)