QAway-to commited on
Commit
90eebc8
·
1 Parent(s): 962e968

App translate 1.2

Browse files
Files changed (1) hide show
  1. app.py +103 -181
app.py CHANGED
@@ -5,7 +5,6 @@ from core.comparer import PortfolioComparer
5
  from core.chat import ChatAssistant
6
  from core.metrics import show_metrics_table
7
  from core.visualization import build_alpha_chart
8
- from core.comparison_table import show_comparison_table
9
 
10
  MODEL_NAME = "meta-llama/Meta-Llama-3.1-8B-Instruct"
11
 
@@ -13,192 +12,115 @@ analyzer = PortfolioAnalyzer(llm_service, MODEL_NAME)
13
  comparer = PortfolioComparer(llm_service, MODEL_NAME)
14
  chatbot = ChatAssistant(llm_service, MODEL_NAME)
15
 
16
- dark_theme = gr.themes.Base(
17
- primary_hue="violet",
18
- secondary_hue="gray",
19
- neutral_hue="zinc",
20
- ).set(
21
- body_background_fill="#0d1117",
22
- body_text_color="#e6edf3",
23
- block_background_fill="#161b22",
24
- block_border_color="#30363d",
25
- button_primary_background_fill="#4f46e5",
26
- button_primary_background_fill_hover="#6366f1",
27
- button_primary_text_color="#ffffff",
28
- input_background_fill="#0d1117",
29
- block_shadow="0 2px 6px rgba(0,0,0,0.3)",
30
- block_label_text_color="#9da5b4",
31
- block_label_text_size="sm",
32
- )
33
-
34
- with gr.Blocks(theme=dark_theme, css="""
35
- /* === unified width (slightly wider than Analysis) === */
36
- .gradio-container {
37
- max-width: 1280px !important;
38
- margin: 0 auto !important;
39
- background: #0d1117 !important;
40
- padding: 20px !important;
41
- font-family: 'Inter', sans-serif;
42
- }
43
- .page {
44
- width: 1140px;
45
- margin: 0 auto;
46
- display: flex;
47
- flex-direction: column;
48
- gap: 14px;
49
- }
50
- .page .gr-textbox,
51
- .page .gr-dataframe,
52
- .page .gr-plot,
53
- .page .gr-button {
54
- width: 100% !important;
 
 
 
 
 
 
 
55
  }
56
 
57
- /* === Textbox styling === */
58
- .page .gr-textbox textarea {
59
- min-height: 400px !important;
60
- resize: none !important;
61
- overflow-y: auto !important;
62
- background: #161b22 !important;
63
- color: #f0f6fc !important;
64
- border: 1px solid #30363d !important;
65
- border-radius: 6px !important;
66
- font-family: 'JetBrains Mono', monospace !important;
67
- font-size: 14px !important;
68
- line-height: 1.5 !important;
69
- }
70
 
71
- /* === Comparison tab: equal height blocks === */
72
- #comment_box textarea {
73
- height: 460px !important;
74
- overflow-y: auto !important;
75
- }
76
- #metrics_table {
77
- height: 460px !important;
78
- overflow: auto !important;
79
- }
80
 
81
- /* === AlphaBTC artefact removal === */
82
- #alpha_chart .modebar,
83
- #alpha_chart .user-select-none {
84
- display: none !important;
85
- }
86
- #alpha_chart svg {
87
- display: none !important;
88
- }
89
- #alpha_chart {
90
- border-radius: 6px !important;
91
- overflow: hidden !important;
92
- background: #161b22 !important;
93
- }
94
 
95
- /* === Buttons === */
96
- .gr-button {
97
- border-radius: 6px !important;
98
- font-weight: 600 !important;
99
- letter-spacing: 0.3px;
100
- box-shadow: 0 2px 4px rgba(0,0,0,0.25);
101
- }
102
- .gr-button.primary {
103
- background: linear-gradient(90deg, #6366f1, #4f46e5);
104
- border: none !important;
105
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
 
107
- /* === Tables === */
108
- .gr-dataframe table {
109
- width: 100% !important;
110
- color: #c9d1d9 !important;
111
- background: #161b22 !important;
112
- }
113
- .gr-dataframe th {
114
- background: #21262d !important;
115
- color: #f0f6fc !important;
116
- font-weight: 600 !important;
117
- text-transform: uppercase;
118
- border-bottom: 1px solid #30363d !important;
119
- }
120
- .gr-dataframe td {
121
- border-top: 1px solid #30363d !important;
122
- padding: 8px !important;
123
- }
124
- """) as demo:
125
-
126
- gr.Markdown("## Investment Portfolio Analyzer")
127
- gr.Markdown(
128
- "A professional dashboard for analyzing and comparing investment portfolios using AI insights.",
129
- elem_classes="subtitle",
130
- )
131
-
132
- with gr.Tabs():
133
-
134
- # --- Analysis ---
135
- with gr.TabItem("Analysis"):
136
- with gr.Column(elem_classes="page"):
137
- portfolio_input = gr.Textbox(
138
- label="Portfolio ID or Link",
139
- placeholder="Enter a portfolio ID (e.g. ea856c1b-...)",
140
- lines=1,
141
- value="b1ef37aa-5b9a-41b4-9394-8823f2de36bb",
142
- )
143
- analyze_button = gr.Button("Run Analysis", variant="primary")
144
- analyze_output = gr.Textbox(label="Analysis Result", lines=15)
145
- analyze_button.click(analyzer.run, inputs=portfolio_input, outputs=analyze_output)
146
-
147
- # --- Comparison Table ---
148
- with gr.TabItem("Comparison Table"):
149
- with gr.Column(elem_classes="page"):
150
- comp_input_1 = gr.Textbox(label="Portfolio A", value="3852a354-e66e-4bc5-97e9-55124e31e687")
151
- comp_input_2 = gr.Textbox(label="Portfolio B", value="b1ef37aa-5b9a-41b4-9394-8823f2de36bb")
152
- comp_button = gr.Button("Load Comparison", variant="primary")
153
-
154
- comp_output_comment = gr.Textbox(
155
- label="AI Commentary",
156
- lines=12,
157
- interactive=True,
158
- show_copy_button=True,
159
- elem_id="comment_box",
160
- )
161
- comp_output_table = gr.Dataframe(
162
- label="Comparative Metrics",
163
- wrap=True,
164
- elem_id="metrics_table",
165
- )
166
-
167
- comp_button.click(
168
- show_comparison_table,
169
- inputs=[comp_input_1, comp_input_2],
170
- outputs=[comp_output_table, comp_output_comment],
171
- )
172
-
173
- # --- Assistant ---
174
- with gr.TabItem("Assistant"):
175
- with gr.Column(elem_classes="page"):
176
- chat_input = gr.Textbox(label="Ask about investments or analysis")
177
- chat_button = gr.Button("Send Question", variant="primary")
178
- chat_output = gr.Textbox(label="AI Response", lines=8)
179
- chat_button.click(chatbot.run, inputs=chat_input, outputs=chat_output)
180
-
181
- # --- Metrics Table ---
182
- with gr.TabItem("Metrics Table"):
183
- with gr.Column(elem_classes="page"):
184
- metrics_input = gr.Textbox(label="Portfolio ID", value="b1ef37aa-5b9a-41b4-9394-8823f2de36bb")
185
- metrics_button = gr.Button("Load Metrics", variant="primary")
186
- metrics_output = gr.Dataframe(label="Portfolio Metrics", wrap=True)
187
- metrics_button.click(show_metrics_table, inputs=metrics_input, outputs=metrics_output)
188
-
189
- # --- AlphaBTC Chart ---
190
- with gr.TabItem("AlphaBTC Chart"):
191
- with gr.Column(elem_classes="page"):
192
- chart_input = gr.Textbox(label="Portfolio ID", value="3852a354-e66e-4bc5-97e9-55124e31e687")
193
- chart_button = gr.Button("Generate Chart", variant="primary")
194
- chart_output = gr.Plot(label="Alpha vs BTC", elem_id="alpha_chart")
195
- chart_button.click(build_alpha_chart, inputs=chart_input, outputs=chart_output)
196
-
197
- gr.Markdown("---")
198
- gr.Markdown(
199
- "<center><small style='color:#6e7681;'>Developed with Featherless.ai • Powered by OpenAI-compatible API</small></center>",
200
- elem_classes="footer",
201
- )
202
 
 
203
  if __name__ == "__main__":
 
204
  demo.launch()
 
5
  from core.chat import ChatAssistant
6
  from core.metrics import show_metrics_table
7
  from core.visualization import build_alpha_chart
 
8
 
9
  MODEL_NAME = "meta-llama/Meta-Llama-3.1-8B-Instruct"
10
 
 
12
  comparer = PortfolioComparer(llm_service, MODEL_NAME)
13
  chatbot = ChatAssistant(llm_service, MODEL_NAME)
14
 
15
+ # === Text dictionaries for RU/ENG ===
16
+ LANG_TEXT = {
17
+ "ENG": {
18
+ "title": "🧠 Investment Portfolio Analysis",
19
+ "tabs": ["📊 Analysis", "⚖️ Comparison", "💬 Chat2", "📋 Metrics Table", "📈 AlphaBTC Chart"],
20
+ "labels": {
21
+ "analyze_input": "Enter portfolioId or link",
22
+ "analyze_button": "🔍 Analyze",
23
+ "analyze_output": "Analysis Result",
24
+ "compare_1": "Portfolio A",
25
+ "compare_2": "Portfolio B",
26
+ "compare_button": "📈 Compare",
27
+ "compare_output": "Comparison Result",
28
+ "chat_input": "Ask your question",
29
+ "chat_button": "Send",
30
+ "chat_output": "Response",
31
+ "metrics_input": "Enter portfolioId",
32
+ "metrics_button": "Show Metrics",
33
+ "metrics_output": "Portfolio Metrics",
34
+ "chart_input": "Enter portfolioId",
35
+ "chart_button": "Plot Chart",
36
+ "chart_output": "Alpha to BTC Chart",
37
+ }
38
+ },
39
+ "RU": {
40
+ "title": "🧠 Анализ инвестиционных портфелей",
41
+ "tabs": ["📊 Анализ", "⚖️ Сравнение", "💬 Диалог", "📋 Таблица метрик", "📈 График AlphaBTC"],
42
+ "labels": {
43
+ "analyze_input": "Введите ссылку или portfolioId",
44
+ "analyze_button": "🔍 Проанализировать",
45
+ "analyze_output": "📈 Результат анализа",
46
+ "compare_1": "Портфель 1",
47
+ "compare_2": "Портфель 2",
48
+ "compare_button": "📊 Сравнить",
49
+ "compare_output": "📉 Результат сравнения",
50
+ "chat_input": "Ваш вопрос",
51
+ "chat_button": "Отправить",
52
+ "chat_output": "Ответ",
53
+ "metrics_input": "Введите portfolioId",
54
+ "metrics_button": "📥 Показать метрики",
55
+ "metrics_output": "📊 Метрики портфеля",
56
+ "chart_input": "Введите portfolioId",
57
+ "chart_button": "Построить график",
58
+ "chart_output": "График Alpha к BTC",
59
+ }
60
+ }
61
  }
62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
 
64
+ def build_interface(lang="ENG"):
65
+ text = LANG_TEXT[lang]
 
 
 
 
 
 
 
66
 
67
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
68
+ lang_state = gr.State(lang)
 
 
 
 
 
 
 
 
 
 
 
69
 
70
+ # Header
71
+ gr.Markdown(f"## {text['title']}")
72
+
73
+ # Language toggle
74
+ lang_button = gr.Button("🌐 Switch Language (RU / ENG)")
75
+
76
+ def switch_language(current_lang):
77
+ return "RU" if current_lang == "ENG" else "ENG"
78
+
79
+ lang_button.click(fn=switch_language, inputs=lang_state, outputs=lang_state).then(
80
+ fn=lambda l: gr.update(visible=False), inputs=lang_state, outputs=None
81
+ )
82
+
83
+ with gr.Tabs():
84
+ # --- Tab 1: Analysis ---
85
+ with gr.TabItem(text["tabs"][0]):
86
+ inp = gr.Textbox(label=text["labels"]["analyze_input"])
87
+ btn = gr.Button(text["labels"]["analyze_button"])
88
+ out = gr.Textbox(label=text["labels"]["analyze_output"], lines=15)
89
+ btn.click(fn=analyzer.run, inputs=inp, outputs=out)
90
+
91
+ # --- Tab 2: Comparison ---
92
+ with gr.TabItem(text["tabs"][1]):
93
+ a = gr.Textbox(label=text["labels"]["compare_1"])
94
+ b = gr.Textbox(label=text["labels"]["compare_2"])
95
+ cmp_btn = gr.Button(text["labels"]["compare_button"])
96
+ cmp_out = gr.Textbox(label=text["labels"]["compare_output"], lines=20)
97
+ cmp_btn.click(fn=comparer.run, inputs=[a, b], outputs=cmp_out)
98
+
99
+ # --- Tab 3: Chat ---
100
+ with gr.TabItem(text["tabs"][2]):
101
+ chat_in = gr.Textbox(label=text["labels"]["chat_input"])
102
+ chat_btn = gr.Button(text["labels"]["chat_button"])
103
+ chat_out = gr.Textbox(label=text["labels"]["chat_output"], lines=8)
104
+ chat_btn.click(fn=chatbot.run, inputs=chat_in, outputs=chat_out)
105
+
106
+ # --- Tab 4: Metrics Table ---
107
+ with gr.TabItem(text["tabs"][3]):
108
+ mid = gr.Textbox(label=text["labels"]["metrics_input"])
109
+ mbtn = gr.Button(text["labels"]["metrics_button"])
110
+ mout = gr.Dataframe(label=text["labels"]["metrics_output"], wrap=True)
111
+ mbtn.click(fn=show_metrics_table, inputs=mid, outputs=mout)
112
+
113
+ # --- Tab 5: AlphaBTC Chart ---
114
+ with gr.TabItem(text["tabs"][4]):
115
+ cid = gr.Textbox(label=text["labels"]["chart_input"], value="3852a354-e66e-4bc5-97e9-55124e31e687")
116
+ cbtn = gr.Button(text["labels"]["chart_button"])
117
+ cout = gr.Plot(label=text["labels"]["chart_output"])
118
+ cbtn.click(fn=build_alpha_chart, inputs=cid, outputs=cout)
119
+
120
+ return demo
121
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
 
123
+ # === Default launch in English ===
124
  if __name__ == "__main__":
125
+ demo = build_interface(lang="ENG")
126
  demo.launch()