QAway-to commited on
Commit
6d49e02
·
1 Parent(s): 5e53674

App translate

Browse files
Files changed (1) hide show
  1. app.py +109 -36
app.py CHANGED
@@ -6,48 +6,121 @@ from core.chat import ChatAssistant
6
  from core.metrics import show_metrics_table
7
  from core.visualization import build_alpha_chart
8
 
9
- # === Model setup ===
10
  MODEL_NAME = "meta-llama/Meta-Llama-3.1-8B-Instruct"
11
 
12
- # === Use case classes ===
13
  analyzer = PortfolioAnalyzer(llm_service, MODEL_NAME)
14
  comparer = PortfolioComparer(llm_service, MODEL_NAME)
15
  chatbot = ChatAssistant(llm_service, MODEL_NAME)
16
 
17
- # === Gradio Interface ===
18
- with gr.Blocks(theme=gr.themes.Soft()) as demo:
19
- gr.Markdown("## 🧠 Анализ инвестиционного портфеля")
20
-
21
- with gr.Tab("📊 Анализ"):
22
- portfolio_input = gr.Textbox(label="Введите ссылку или portfolioId", placeholder="ea856c1b-...")
23
- analyze_button = gr.Button("🔍 Проанализировать")
24
- analyze_output = gr.Textbox(label="📈 Результат анализа", lines=15)
25
- analyze_button.click(fn=analyzer.run, inputs=portfolio_input, outputs=analyze_output)
26
-
27
- with gr.Tab("⚖️ Сравнение"):
28
- compare_input_1 = gr.Textbox(label="Портфель 1", placeholder="ea856c1b-...")
29
- compare_input_2 = gr.Textbox(label="Портфель 2", placeholder="d52f55cc-...")
30
- compare_button = gr.Button("📊 Сравнить")
31
- compare_output = gr.Textbox(label="📉 Результат сравнения", lines=20)
32
- compare_button.click(fn=comparer.run, inputs=[compare_input_1, compare_input_2], outputs=compare_output)
33
-
34
- with gr.Tab("💬 Диалог"):
35
- chat_input = gr.Textbox(label="Ваш вопрос", placeholder="Дай ссылки на финансовые платформы")
36
- chat_button = gr.Button("Отправить")
37
- chat_output = gr.Textbox(label="Ответ", lines=8)
38
- chat_button.click(fn=chatbot.run, inputs=chat_input, outputs=chat_output)
39
-
40
- with gr.Tab("📋 Таблица метрик"):
41
- metrics_input = gr.Textbox(label="Введите portfolioId", placeholder="ea856c1b-...")
42
- metrics_button = gr.Button("📥 Показать метрики")
43
- metrics_output = gr.Dataframe(label="📊 Метрики портфеля", wrap=True)
44
- metrics_button.click(fn=show_metrics_table, inputs=metrics_input, outputs=metrics_output)
45
-
46
- with gr.Tab("📈 AlphaBTC график"):
47
- chart_input = gr.Textbox(label="Введите portfolioId", value="3852a354-e66e-4bc5-97e9-55124e31e687")
48
- chart_button = gr.Button("Построить график")
49
- chart_output = gr.Plot(label="График Alpha к BTC")
50
- chart_button.click(fn=build_alpha_chart, inputs=chart_input, outputs=chart_output)
 
 
 
 
 
 
 
 
 
 
 
 
 
51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  if __name__ == "__main__":
 
53
  demo.launch()
 
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
 
 
11
  analyzer = PortfolioAnalyzer(llm_service, MODEL_NAME)
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", "💬 Chat", "📋 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()