Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
import requests
|
| 4 |
import os
|
| 5 |
import datetime
|
|
@@ -41,33 +41,37 @@ def fetch_crypto_data(crypto):
|
|
| 41 |
return crypto_dates, crypto_prices
|
| 42 |
|
| 43 |
|
| 44 |
-
def
|
| 45 |
-
"""Plots the historical price data for
|
| 46 |
-
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
plt.legend()
|
| 60 |
-
plt.grid()
|
| 61 |
|
| 62 |
-
return
|
| 63 |
|
| 64 |
# Create Gradio Interface
|
| 65 |
demo = gr.Interface(
|
| 66 |
-
fn=
|
| 67 |
-
inputs=
|
| 68 |
outputs=gr.Plot(label="Price Chart"),
|
| 69 |
title="Cryptocurrency Price Visualization",
|
| 70 |
-
description="
|
| 71 |
)
|
| 72 |
|
| 73 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import plotly.graph_objects as go
|
| 3 |
import requests
|
| 4 |
import os
|
| 5 |
import datetime
|
|
|
|
| 41 |
return crypto_dates, crypto_prices
|
| 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)
|
| 50 |
+
|
| 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__":
|