Spaces:
Sleeping
Sleeping
QAway-to
commited on
Commit
·
306a1b2
1
Parent(s):
d969426
New tabs and functions v4.2
Browse files
app.py
CHANGED
|
@@ -4,6 +4,8 @@ from core.analyzer import PortfolioAnalyzer
|
|
| 4 |
from core.comparer import PortfolioComparer
|
| 5 |
from core.chat import ChatAssistant
|
| 6 |
from core.metrics import show_metrics_table
|
|
|
|
|
|
|
| 7 |
from core.crypto_dashboard import build_crypto_dashboard # (обновлено: KPI-line + более плотные графики)
|
| 8 |
from core.multi_charts import build_echarts_html, build_highcharts_html # (обновлено: чистый HTML/JS)
|
| 9 |
|
|
@@ -63,29 +65,10 @@ with gr.Blocks(css=base_css) as demo:
|
|
| 63 |
metrics_out = gr.Dataframe(label="Portfolio Metrics", wrap=True)
|
| 64 |
metrics_btn.click(fn=show_metrics_table, inputs=metrics_in, outputs=metrics_out)
|
| 65 |
|
| 66 |
-
# --- Visual Comparison (BTC vs ETH Plotly Edition) ---
|
| 67 |
-
with gr.TabItem("Visual Comparison (BTC vs ETH)"):
|
| 68 |
-
gr.Markdown("### 📈 BTC vs ETH — Market Comparison (Plotly Edition)")
|
| 69 |
-
|
| 70 |
-
from core.visual_comparison import build_comparison_chart, build_volatility_chart
|
| 71 |
-
|
| 72 |
-
compare_btn = gr.Button("Generate Comparison", variant="primary")
|
| 73 |
-
price_plot = gr.Plot(label="Price Trend (BTC vs ETH)")
|
| 74 |
-
vol_plot = gr.Plot(label="Daily Volatility (%)")
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
def run_visuals():
|
| 78 |
-
return build_comparison_chart(), build_volatility_chart()
|
| 79 |
-
|
| 80 |
-
compare_btn.click(fn=run_visuals, outputs=[price_plot, vol_plot])
|
| 81 |
-
|
| 82 |
# --- Visual Comparison (Plotly Edition, Auto & Interactive) ---
|
| 83 |
with gr.TabItem("Visual Comparison"):
|
| 84 |
gr.Markdown("### 📊 Market Pair Comparison — BTC vs ETH (default)")
|
| 85 |
|
| 86 |
-
from core.visual_comparison import build_price_chart, build_volatility_chart
|
| 87 |
-
|
| 88 |
-
# Список популярных активов
|
| 89 |
available_pairs = [
|
| 90 |
("bitcoin", "ethereum"),
|
| 91 |
("bitcoin", "solana"),
|
|
@@ -94,7 +77,6 @@ with gr.Blocks(css=base_css) as demo:
|
|
| 94 |
("bitcoin", "toncoin"),
|
| 95 |
]
|
| 96 |
|
| 97 |
-
# Выпадающий список выбора пары
|
| 98 |
pair_selector = gr.Dropdown(
|
| 99 |
label="Select Pair for Comparison",
|
| 100 |
choices=[f"{a.capitalize()} vs {b.capitalize()}" for a, b in available_pairs],
|
|
@@ -102,25 +84,20 @@ with gr.Blocks(css=base_css) as demo:
|
|
| 102 |
interactive=True,
|
| 103 |
)
|
| 104 |
|
| 105 |
-
# Два графика: цена и волатильность
|
| 106 |
price_plot = gr.Plot(label="Price Comparison")
|
| 107 |
vol_plot = gr.Plot(label="Volatility Comparison")
|
| 108 |
|
| 109 |
|
| 110 |
-
# Функция обновления графиков
|
| 111 |
def update_visuals(selected_pair: str):
|
| 112 |
for a, b in available_pairs:
|
| 113 |
if selected_pair.lower() == f"{a} vs {b}":
|
| 114 |
return build_price_chart((a, b)), build_volatility_chart((a, b))
|
| 115 |
-
# fallback — если вдруг не найдено
|
| 116 |
return build_price_chart(("bitcoin", "ethereum")), build_volatility_chart(("bitcoin", "ethereum"))
|
| 117 |
|
| 118 |
|
| 119 |
-
# Связываем обновление графиков при смене пары
|
| 120 |
pair_selector.change(fn=update_visuals, inputs=pair_selector, outputs=[price_plot, vol_plot])
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
demo.load(fn=update_visuals, inputs=None, outputs=[price_plot, vol_plot], _js="() => 'Bitcoin vs Ethereum'")
|
| 124 |
|
| 125 |
if __name__ == "__main__":
|
| 126 |
demo.launch()
|
|
|
|
| 4 |
from core.comparer import PortfolioComparer
|
| 5 |
from core.chat import ChatAssistant
|
| 6 |
from core.metrics import show_metrics_table
|
| 7 |
+
from core.crypto_dashboard import build_crypto_dashboard
|
| 8 |
+
from core.visual_comparison import build_price_chart, build_volatility_chart # ✅ сюда!
|
| 9 |
from core.crypto_dashboard import build_crypto_dashboard # (обновлено: KPI-line + более плотные графики)
|
| 10 |
from core.multi_charts import build_echarts_html, build_highcharts_html # (обновлено: чистый HTML/JS)
|
| 11 |
|
|
|
|
| 65 |
metrics_out = gr.Dataframe(label="Portfolio Metrics", wrap=True)
|
| 66 |
metrics_btn.click(fn=show_metrics_table, inputs=metrics_in, outputs=metrics_out)
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
# --- Visual Comparison (Plotly Edition, Auto & Interactive) ---
|
| 69 |
with gr.TabItem("Visual Comparison"):
|
| 70 |
gr.Markdown("### 📊 Market Pair Comparison — BTC vs ETH (default)")
|
| 71 |
|
|
|
|
|
|
|
|
|
|
| 72 |
available_pairs = [
|
| 73 |
("bitcoin", "ethereum"),
|
| 74 |
("bitcoin", "solana"),
|
|
|
|
| 77 |
("bitcoin", "toncoin"),
|
| 78 |
]
|
| 79 |
|
|
|
|
| 80 |
pair_selector = gr.Dropdown(
|
| 81 |
label="Select Pair for Comparison",
|
| 82 |
choices=[f"{a.capitalize()} vs {b.capitalize()}" for a, b in available_pairs],
|
|
|
|
| 84 |
interactive=True,
|
| 85 |
)
|
| 86 |
|
|
|
|
| 87 |
price_plot = gr.Plot(label="Price Comparison")
|
| 88 |
vol_plot = gr.Plot(label="Volatility Comparison")
|
| 89 |
|
| 90 |
|
|
|
|
| 91 |
def update_visuals(selected_pair: str):
|
| 92 |
for a, b in available_pairs:
|
| 93 |
if selected_pair.lower() == f"{a} vs {b}":
|
| 94 |
return build_price_chart((a, b)), build_volatility_chart((a, b))
|
|
|
|
| 95 |
return build_price_chart(("bitcoin", "ethereum")), build_volatility_chart(("bitcoin", "ethereum"))
|
| 96 |
|
| 97 |
|
|
|
|
| 98 |
pair_selector.change(fn=update_visuals, inputs=pair_selector, outputs=[price_plot, vol_plot])
|
| 99 |
+
demo.load(fn=update_visuals, inputs=None, outputs=[price_plot, vol_plot],
|
| 100 |
+
_js="() => 'Bitcoin vs Ethereum'")
|
|
|
|
| 101 |
|
| 102 |
if __name__ == "__main__":
|
| 103 |
demo.launch()
|