dibend commited on
Commit
1f79e01
·
verified ·
1 Parent(s): 3b32be9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -16
app.py CHANGED
@@ -42,8 +42,8 @@ def fetch_crypto_data(crypto):
42
 
43
 
44
  def plot_crypto_prices():
45
- """Plots the historical price data for all selected cryptocurrencies."""
46
- fig = go.Figure()
47
 
48
  for crypto in cryptos:
49
  crypto_dates, crypto_prices = fetch_crypto_data(crypto)
@@ -51,28 +51,34 @@ def plot_crypto_prices():
51
  if isinstance(crypto_dates, str):
52
  continue # Skip on error
53
 
54
- color = random.choice(colors)
55
- fig.add_trace(go.Scatter(x=crypto_dates, y=crypto_prices, mode='lines', name=crypto, line=dict(color=color)))
 
 
 
 
56
 
57
- fig.update_layout(
58
- title="Cryptocurrency Price History",
59
- xaxis_title="Date",
60
- yaxis_title="Price (USD)",
61
- template="plotly_dark",
62
- xaxis=dict(tickangle=-45),
63
- legend_title="Cryptos"
64
- )
 
 
65
 
66
- return fig
67
 
68
  # Create Gradio Interface
69
  demo = gr.Interface(
70
  fn=plot_crypto_prices,
71
  inputs=[],
72
- outputs=gr.Plot(label="Price Chart"),
73
  title="Cryptocurrency Price Visualization",
74
- description="Displays historical price data for multiple cryptocurrencies over the past year."
75
  )
76
 
77
  if __name__ == "__main__":
78
- demo.launch()
 
42
 
43
 
44
  def plot_crypto_prices():
45
+ """Creates individual plots for each cryptocurrency with a filled area below the line."""
46
+ figures = []
47
 
48
  for crypto in cryptos:
49
  crypto_dates, crypto_prices = fetch_crypto_data(crypto)
 
51
  if isinstance(crypto_dates, str):
52
  continue # Skip on error
53
 
54
+ line_color = random.choice(colors)
55
+ fill_color = random.choice(colors)
56
+
57
+ fig = go.Figure()
58
+ fig.add_trace(go.Scatter(x=crypto_dates, y=crypto_prices, mode='lines', name=crypto, line=dict(color=line_color)))
59
+ fig.add_trace(go.Scatter(x=crypto_dates, y=crypto_prices, fill='tozeroy', fillcolor=fill_color, mode='none', name=f"{crypto} Fill"))
60
 
61
+ fig.update_layout(
62
+ title=f"{crypto} Price History",
63
+ xaxis_title="Date",
64
+ yaxis_title="Price (USD)",
65
+ template="plotly_dark",
66
+ xaxis=dict(tickangle=-45),
67
+ legend_title=crypto
68
+ )
69
+
70
+ figures.append(fig)
71
 
72
+ return figures
73
 
74
  # Create Gradio Interface
75
  demo = gr.Interface(
76
  fn=plot_crypto_prices,
77
  inputs=[],
78
+ outputs=[gr.Plot(label=f"{crypto} Price Chart") for crypto in cryptos],
79
  title="Cryptocurrency Price Visualization",
80
+ description="Displays historical price data for multiple cryptocurrencies over the past year, with filled areas below the lines."
81
  )
82
 
83
  if __name__ == "__main__":
84
+ demo.launch(debug=True)