QAway-to commited on
Commit
a41be0f
·
1 Parent(s): 306a1b2

New tabs and functions v4.3

Browse files
Files changed (1) hide show
  1. app.py +77 -33
app.py CHANGED
@@ -4,8 +4,6 @@ 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
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,39 +63,85 @@ with gr.Blocks(css=base_css) as demo:
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 ComparisonBTC vs ETH (default)")
71
-
72
- available_pairs = [
73
- ("bitcoin", "ethereum"),
74
- ("bitcoin", "solana"),
75
- ("ethereum", "bnb"),
76
- ("solana", "dogecoin"),
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],
83
- value="Bitcoin vs Ethereum",
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()
 
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
  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 ETHMarket 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
+ # --- Crypto Intelligence Dashboard (Plotly Edition + KPI line) ---
83
+ with gr.TabItem("Crypto Intelligence Dashboard"):
84
+ # Подключаем стили вкладки
85
+ gr.HTML(f"<style>{crypto_css}</style>")
86
+
87
+ # KPI line (фиксированная строка без скачков, с минимальными отступами)
88
+ with gr.Row(elem_id="kpi_row"):
89
+ kpi_line = gr.HTML(elem_id="kpi_line")
90
+
91
+ # Controls (Top N slider + кнопка)
92
+ with gr.Row(elem_id="controls_row"):
93
+ top_slider = gr.Slider(
94
+ label="Top N coins",
95
+ minimum=20,
96
+ maximum=100,
97
+ step=10,
98
+ value=50,
99
+ scale=70,
100
+ )
101
+ load_btn = gr.Button("Generate Dashboard", variant="primary", scale=30)
102
+
103
+ # Основной контент — графики и текстовый инсайт
104
+ with gr.Row(equal_height=True, elem_id="main_charts_row"):
105
+ with gr.Column(scale=70):
106
+ treemap_plot = gr.Plot(label="Market Composition")
107
+ with gr.Column(scale=30):
108
+ ai_box = gr.Textbox(
109
+ label="AI Market Summary",
110
+ lines=18,
111
+ elem_id="ai_summary_sidebar",
112
+ )
113
+
114
+ # Нижний ряд с двумя графиками
115
+ with gr.Row(equal_height=True, elem_id="bottom_charts_row"):
116
+ movers_plot = gr.Plot(label="Top Movers", scale=50)
117
+ scatter_plot = gr.Plot(label="Market Cap vs Volume", scale=50)
118
+
119
+
120
+ # === Callback ===
121
+ def run_dash(n):
122
+ fig_treemap, fig_bar, fig_bubble, ai_comment, kpi_text = build_crypto_dashboard(n)
123
+ # KPI-строка уже готова, возвращаем её с обёрткой <div>
124
+ return (
125
+ fig_treemap,
126
+ fig_bar,
127
+ fig_bubble,
128
+ ai_comment,
129
+ f"<div class='kpi-line'>{kpi_text}</div>",
130
+ )
131
+
132
+
133
+ load_btn.click(
134
+ fn=run_dash,
135
+ inputs=top_slider,
136
+ outputs=[treemap_plot, movers_plot, scatter_plot, ai_box, kpi_line],
137
+ show_progress="minimal",
138
  )
139
 
140
+ gr.Markdown("---")
141
+ gr.Markdown(
142
+ "<center><small style='color:#6e7681;'>Developed with Featherless.ai • Powered by OpenAI-compatible API</small></center>",
143
+ elem_classes="footer",
144
+ )
 
 
 
 
 
 
 
 
 
145
 
146
  if __name__ == "__main__":
147
  demo.launch()