Spaces:
Sleeping
Sleeping
QAway-to
commited on
Commit
·
eb2bf76
1
Parent(s):
e1e57ed
New style APP
Browse files
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 |
-
# ===
|
| 16 |
-
|
| 17 |
-
"
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 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 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
#
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 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()
|