QAway-to commited on
Commit
eb2bf76
·
1 Parent(s): e1e57ed

New style APP

Browse files
Files changed (1) hide show
  1. app.py +86 -114
app.py CHANGED
@@ -12,121 +12,93 @@ analyzer = PortfolioAnalyzer(llm_service, MODEL_NAME)
12
  comparer = PortfolioComparer(llm_service, MODEL_NAME)
13
  chatbot = ChatAssistant(llm_service, MODEL_NAME)
14
 
15
- # === Language texts ===
16
- LANG = {
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
- "switch": "🌐 Switch to Russian",
39
- },
40
- "RU": {
41
- "title": "🧠 Анализ инвестиционных портфелей",
42
- "tabs": ["📊 Анализ", "⚖️ Сравнение", "💬 Диалог", "📋 Таблица метрик", "📈 График AlphaBTC"],
43
- "labels": {
44
- "analyze_input": "Введите ссылку или portfolioId",
45
- "analyze_button": "🔍 Проанализировать",
46
- "analyze_output": "📈 Результат анализа",
47
- "compare_1": "Портфель 1",
48
- "compare_2": "Портфель 2",
49
- "compare_button": "📊 Сравнить",
50
- "compare_output": "📉 Результат сравнения",
51
- "chat_input": "Ваш вопрос",
52
- "chat_button": "Отправить",
53
- "chat_output": "Ответ",
54
- "metrics_input": "Введите portfolioId",
55
- "metrics_button": "📥 Показать метрики",
56
- "metrics_output": "📊 Метрики портфеля",
57
- "chart_input": "Введите portfolioId",
58
- "chart_button": "Построить график",
59
- "chart_output": "График Alpha к BTC",
60
- },
61
- "switch": "🌐 Switch to English",
62
- },
63
  }
64
-
65
-
66
- def build_interface(lang="ENG"):
67
- """Rebuild interface based on selected language."""
68
- text = LANG[lang]
69
-
70
- with gr.Blocks(theme=gr.themes.Soft()) as demo:
71
- lang_state = gr.State(lang)
72
-
73
- # Header
74
- gr.Markdown(f"## {text['title']}")
75
-
76
- # Language toggle
77
- def toggle_language(current_lang):
78
- return "RU" if current_lang == "ENG" else "ENG"
79
-
80
- # Button to rebuild interface
81
- switch_button = gr.Button(text["switch"])
82
-
83
- # Rebuild full interface recursively when button clicked
84
- switch_button.click(
85
- fn=lambda l: build_interface("RU" if l == "ENG" else "ENG"),
86
- inputs=lang_state,
87
- outputs=None,
88
- )
89
-
90
- with gr.Tabs():
91
- # --- Tab 1: Analysis ---
92
- with gr.TabItem(text["tabs"][0]):
93
- inp = gr.Textbox(label=text["labels"]["analyze_input"])
94
- btn = gr.Button(text["labels"]["analyze_button"])
95
- out = gr.Textbox(label=text["labels"]["analyze_output"], lines=15)
96
- btn.click(fn=analyzer.run, inputs=inp, outputs=out)
97
-
98
- # --- Tab 2: Comparison ---
99
- with gr.TabItem(text["tabs"][1]):
100
- a = gr.Textbox(label=text["labels"]["compare_1"])
101
- b = gr.Textbox(label=text["labels"]["compare_2"])
102
- cmp_btn = gr.Button(text["labels"]["compare_button"])
103
- cmp_out = gr.Textbox(label=text["labels"]["compare_output"], lines=20)
104
- cmp_btn.click(fn=comparer.run, inputs=[a, b], outputs=cmp_out)
105
-
106
- # --- Tab 3: Chat ---
107
- with gr.TabItem(text["tabs"][2]):
108
- chat_in = gr.Textbox(label=text["labels"]["chat_input"])
109
- chat_btn = gr.Button(text["labels"]["chat_button"])
110
- chat_out = gr.Textbox(label=text["labels"]["chat_output"], lines=8)
111
- chat_btn.click(fn=chatbot.run, inputs=chat_in, outputs=chat_out)
112
-
113
- # --- Tab 4: Metrics Table ---
114
- with gr.TabItem(text["tabs"][3]):
115
- mid = gr.Textbox(label=text["labels"]["metrics_input"])
116
- mbtn = gr.Button(text["labels"]["metrics_button"])
117
- mout = gr.Dataframe(label=text["labels"]["metrics_output"], wrap=True)
118
- mbtn.click(fn=show_metrics_table, inputs=mid, outputs=mout)
119
-
120
- # --- Tab 5: AlphaBTC Chart ---
121
- with gr.TabItem(text["tabs"][4]):
122
- cid = gr.Textbox(label=text["labels"]["chart_input"], value="3852a354-e66e-4bc5-97e9-55124e31e687")
123
- cbtn = gr.Button(text["labels"]["chart_button"])
124
- cout = gr.Plot(label=text["labels"]["chart_output"])
125
- cbtn.click(fn=build_alpha_chart, inputs=cid, outputs=cout)
126
-
127
- return demo
128
-
129
 
130
  if __name__ == "__main__":
131
- demo = build_interface("ENG")
132
  demo.launch()
 
12
  comparer = PortfolioComparer(llm_service, MODEL_NAME)
13
  chatbot = ChatAssistant(llm_service, MODEL_NAME)
14
 
15
+ # === Custom theme configuration ===
16
+ custom_theme = gr.themes.Base(
17
+ primary_hue="indigo",
18
+ secondary_hue="gray",
19
+ neutral_hue="zinc",
20
+ ).set(
21
+ body_background_fill="#f8f9fa",
22
+ body_text_color="#222",
23
+ block_background_fill="#ffffff",
24
+ block_border_width="1px",
25
+ block_border_color="#e5e7eb",
26
+ button_primary_background_fill="#4f46e5",
27
+ button_primary_text_color="white",
28
+ button_primary_background_fill_hover="#4338ca",
29
+ block_shadow="0 2px 6px rgba(0,0,0,0.05)",
30
+ block_label_text_size="lg",
31
+ block_label_text_weight="600",
32
+ )
33
+
34
+ # === Interface ===
35
+ with gr.Blocks(theme=custom_theme, css="""
36
+ .gradio-container {
37
+ max-width: 900px !important;
38
+ margin: auto !important;
39
+ font-family: 'Inter', sans-serif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  }
41
+ h2, h3, .gr-markdown {
42
+ font-weight: 600;
43
+ }
44
+ .gr-button {
45
+ border-radius: 6px !important;
46
+ font-weight: 600 !important;
47
+ letter-spacing: 0.2px;
48
+ }
49
+ """) as demo:
50
+ gr.Markdown("## Investment Portfolio Analyzer")
51
+ gr.Markdown(
52
+ "A lightweight interface for analyzing and comparing investment portfolios with AI assistance.",
53
+ elem_classes="subtitle",
54
+ )
55
+
56
+ with gr.Tabs():
57
+ # --- Analysis Tab ---
58
+ with gr.TabItem("Analysis"):
59
+ portfolio_input = gr.Textbox(
60
+ label="Portfolio ID or Link",
61
+ placeholder="Enter a portfolio ID (e.g. ea856c1b-...)",
62
+ lines=1,
63
+ )
64
+ analyze_button = gr.Button("Run Analysis", variant="primary")
65
+ analyze_output = gr.Textbox(label="Analysis Result", lines=15)
66
+ analyze_button.click(fn=analyzer.run, inputs=portfolio_input, outputs=analyze_output)
67
+
68
+ # --- Comparison Tab ---
69
+ with gr.TabItem("Comparison"):
70
+ compare_input_1 = gr.Textbox(label="Portfolio A")
71
+ compare_input_2 = gr.Textbox(label="Portfolio B")
72
+ compare_button = gr.Button("Compare Portfolios", variant="primary")
73
+ compare_output = gr.Textbox(label="Comparison Result", lines=20)
74
+ compare_button.click(fn=comparer.run, inputs=[compare_input_1, compare_input_2], outputs=compare_output)
75
+
76
+ # --- Chat Assistant Tab ---
77
+ with gr.TabItem("Assistant"):
78
+ chat_input = gr.Textbox(label="Ask about investments or analysis")
79
+ chat_button = gr.Button("Send Question", variant="primary")
80
+ chat_output = gr.Textbox(label="AI Response", lines=8)
81
+ chat_button.click(fn=chatbot.run, inputs=chat_input, outputs=chat_output)
82
+
83
+ # --- Metrics Table Tab ---
84
+ with gr.TabItem("Metrics Table"):
85
+ metrics_input = gr.Textbox(label="Portfolio ID")
86
+ metrics_button = gr.Button("Load Metrics", variant="primary")
87
+ metrics_output = gr.Dataframe(label="Portfolio Metrics", wrap=True)
88
+ metrics_button.click(fn=show_metrics_table, inputs=metrics_input, outputs=metrics_output)
89
+
90
+ # --- AlphaBTC Chart Tab ---
91
+ with gr.TabItem("AlphaBTC Chart"):
92
+ chart_input = gr.Textbox(label="Portfolio ID", value="3852a354-e66e-4bc5-97e9-55124e31e687")
93
+ chart_button = gr.Button("Generate Chart", variant="primary")
94
+ chart_output = gr.Plot(label="Alpha vs BTC")
95
+ chart_button.click(fn=build_alpha_chart, inputs=chart_input, outputs=chart_output)
96
+
97
+ gr.Markdown("---")
98
+ gr.Markdown(
99
+ "<center><small>Developed with Featherless.ai • Powered by OpenAI-compatible API</small></center>",
100
+ elem_classes="footer",
101
+ )
 
 
 
 
102
 
103
  if __name__ == "__main__":
 
104
  demo.launch()