Spaces:
Running
Running
QAway-to
commited on
Commit
·
cdab94b
1
Parent(s):
d586eea
New style APP (Tab Changes v3.0)
Browse files- .idea/TradeLinkAI.iml +5 -4
- .idea/modules.xml +8 -0
- app.py +94 -118
.idea/TradeLinkAI.iml
CHANGED
|
@@ -1,7 +1,8 @@
|
|
| 1 |
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
-
<module version="4">
|
| 3 |
-
<component name="
|
| 4 |
-
<
|
| 5 |
-
<
|
|
|
|
| 6 |
</component>
|
| 7 |
</module>
|
|
|
|
| 1 |
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<module type="PYTHON_MODULE" version="4">
|
| 3 |
+
<component name="NewModuleRootManager">
|
| 4 |
+
<content url="file://$MODULE_DIR$" />
|
| 5 |
+
<orderEntry type="inheritedJdk" />
|
| 6 |
+
<orderEntry type="sourceFolder" forTests="false" />
|
| 7 |
</component>
|
| 8 |
</module>
|
.idea/modules.xml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="ProjectModuleManager">
|
| 4 |
+
<modules>
|
| 5 |
+
<module fileurl="file://$PROJECT_DIR$/.idea/TradeLinkAI.iml" filepath="$PROJECT_DIR$/.idea/TradeLinkAI.iml" />
|
| 6 |
+
</modules>
|
| 7 |
+
</component>
|
| 8 |
+
</project>
|
app.py
CHANGED
|
@@ -5,6 +5,7 @@ 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 |
|
| 9 |
MODEL_NAME = "meta-llama/Meta-Llama-3.1-8B-Instruct"
|
| 10 |
|
|
@@ -18,11 +19,11 @@ dark_theme = gr.themes.Base(
|
|
| 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",
|
|
@@ -31,34 +32,17 @@ dark_theme = gr.themes.Base(
|
|
| 31 |
block_label_text_size="sm",
|
| 32 |
)
|
| 33 |
|
| 34 |
-
with gr.Blocks(
|
| 35 |
-
|
|
|
|
|
|
|
| 36 |
.gradio-container {
|
| 37 |
-
max-width:
|
| 38 |
margin: auto !important;
|
| 39 |
font-family: 'Inter', sans-serif;
|
| 40 |
background-color: #0d1117 !important;
|
| 41 |
}
|
| 42 |
-
/* === LLM Commentary Styling === */
|
| 43 |
-
#llm_comment_box textarea {
|
| 44 |
-
max-height: 420px !important; /* ограничение высоты */
|
| 45 |
-
overflow-y: auto !important; /* вертикальный скроллинг */
|
| 46 |
-
background-color: #161b22 !important;
|
| 47 |
-
color: #f0f6fc !important;
|
| 48 |
-
border: 1px solid #30363d !important;
|
| 49 |
-
border-radius: 6px !important;
|
| 50 |
-
font-family: 'JetBrains Mono', monospace !important;
|
| 51 |
-
font-size: 14px !important;
|
| 52 |
-
line-height: 1.5 !important;
|
| 53 |
-
padding: 12px !important;
|
| 54 |
-
}
|
| 55 |
-
/* === Comparison Table === */
|
| 56 |
-
#comparison_table {
|
| 57 |
-
margin-top: 8px !important;
|
| 58 |
-
}
|
| 59 |
-
|
| 60 |
h2, h3, .gr-markdown {
|
| 61 |
-
font-weight: 600;
|
| 62 |
color: #f0f6fc !important;
|
| 63 |
}
|
| 64 |
.gr-button {
|
|
@@ -70,48 +54,38 @@ h2, h3, .gr-markdown {
|
|
| 70 |
.gr-textbox, .gr-dataframe {
|
| 71 |
border-radius: 6px !important;
|
| 72 |
}
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
}
|
| 81 |
-
.gr-tabs {
|
| 82 |
-
border-bottom: 1px solid #30363d !important;
|
| 83 |
-
}
|
| 84 |
-
.gr-plot {
|
| 85 |
-
background: #0d1117 !important;
|
| 86 |
-
}
|
| 87 |
-
/* Fix Gradio plot overlay */
|
| 88 |
-
#alpha_chart svg {
|
| 89 |
-
display: none !important;
|
| 90 |
-
}
|
| 91 |
-
#alpha_chart .wrap {
|
| 92 |
-
background: transparent !important;
|
| 93 |
-
box-shadow: none !important;
|
| 94 |
-
}
|
| 95 |
-
/* === Styled comparison table === */
|
| 96 |
-
.gr-dataframe table {
|
| 97 |
-
border-collapse: collapse !important;
|
| 98 |
-
width: 100% !important;
|
| 99 |
-
color: #c9d1d9 !important;
|
| 100 |
-
background-color: #161b22 !important;
|
| 101 |
}
|
| 102 |
-
.gr-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
text-transform: uppercase;
|
| 107 |
-
border-bottom: 1px solid #30363d !important;
|
| 108 |
}
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
}
|
| 113 |
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
gr.Markdown("## Investment Portfolio Analyzer")
|
| 116 |
gr.Markdown(
|
| 117 |
"A professional dashboard for analyzing and comparing investment portfolios using AI insights.",
|
|
@@ -121,73 +95,75 @@ h2, h3, .gr-markdown {
|
|
| 121 |
with gr.Tabs():
|
| 122 |
# --- Analysis Tab ---
|
| 123 |
with gr.TabItem("Analysis"):
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
|
| 134 |
# --- Comparison Table Tab ---
|
| 135 |
with gr.TabItem("Comparison Table"):
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
outputs=[comp_output_table, comp_output_comment],
|
| 161 |
-
)
|
| 162 |
|
| 163 |
# --- Chat Assistant Tab ---
|
| 164 |
with gr.TabItem("Assistant"):
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
|
|
|
| 169 |
|
| 170 |
# --- Metrics Table Tab ---
|
| 171 |
with gr.TabItem("Metrics Table"):
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
|
|
|
| 176 |
|
| 177 |
-
# --- AlphaBTC Chart Tab
|
| 178 |
with gr.TabItem("AlphaBTC Chart"):
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
label="Alpha vs BTC",
|
| 183 |
-
|
| 184 |
-
elem_id="alpha_chart",
|
| 185 |
-
)
|
| 186 |
-
chart_button.click(fn=build_alpha_chart, inputs=chart_input, outputs=chart_output)
|
| 187 |
|
| 188 |
gr.Markdown("---")
|
| 189 |
gr.Markdown(
|
| 190 |
-
"<center><small
|
| 191 |
elem_classes="footer",
|
| 192 |
)
|
| 193 |
|
|
|
|
| 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 |
|
|
|
|
| 19 |
secondary_hue="gray",
|
| 20 |
neutral_hue="zinc",
|
| 21 |
).set(
|
| 22 |
+
body_background_fill="#0d1117",
|
| 23 |
+
body_text_color="#e6edf3",
|
| 24 |
+
block_background_fill="#161b22",
|
| 25 |
+
block_border_color="#30363d",
|
| 26 |
+
button_primary_background_fill="#4f46e5",
|
| 27 |
button_primary_background_fill_hover="#6366f1",
|
| 28 |
button_primary_text_color="#ffffff",
|
| 29 |
input_background_fill="#0d1117",
|
|
|
|
| 32 |
block_label_text_size="sm",
|
| 33 |
)
|
| 34 |
|
| 35 |
+
with gr.Blocks(
|
| 36 |
+
theme=dark_theme,
|
| 37 |
+
css="""
|
| 38 |
+
/* === Unified Finance UI === */
|
| 39 |
.gradio-container {
|
| 40 |
+
max-width: 1100px !important;
|
| 41 |
margin: auto !important;
|
| 42 |
font-family: 'Inter', sans-serif;
|
| 43 |
background-color: #0d1117 !important;
|
| 44 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
h2, h3, .gr-markdown {
|
|
|
|
| 46 |
color: #f0f6fc !important;
|
| 47 |
}
|
| 48 |
.gr-button {
|
|
|
|
| 54 |
.gr-textbox, .gr-dataframe {
|
| 55 |
border-radius: 6px !important;
|
| 56 |
}
|
| 57 |
+
|
| 58 |
+
/* === Unified block layout === */
|
| 59 |
+
.block-section {
|
| 60 |
+
display: flex;
|
| 61 |
+
flex-direction: column;
|
| 62 |
+
gap: 12px;
|
| 63 |
+
min-height: 520px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
}
|
| 65 |
+
.gr-textbox textarea {
|
| 66 |
+
min-height: 420px !important;
|
| 67 |
+
resize: none !important;
|
| 68 |
+
overflow-y: auto !important;
|
|
|
|
|
|
|
| 69 |
}
|
| 70 |
+
|
| 71 |
+
/* === Comparison / Analysis boxes alignment === */
|
| 72 |
+
#llm_comment_box textarea,
|
| 73 |
+
#comparison_table,
|
| 74 |
+
#analysis_output textarea,
|
| 75 |
+
#chat_output textarea {
|
| 76 |
+
min-height: 400px !important;
|
| 77 |
+
overflow-y: auto !important;
|
| 78 |
+
font-family: 'JetBrains Mono', monospace !important;
|
| 79 |
+
font-size: 14px !important;
|
| 80 |
}
|
| 81 |
|
| 82 |
+
/* === Footer === */
|
| 83 |
+
.footer small {
|
| 84 |
+
color: #6e7681 !important;
|
| 85 |
+
text-align: center;
|
| 86 |
+
}
|
| 87 |
+
"""
|
| 88 |
+
) as demo:
|
| 89 |
gr.Markdown("## Investment Portfolio Analyzer")
|
| 90 |
gr.Markdown(
|
| 91 |
"A professional dashboard for analyzing and comparing investment portfolios using AI insights.",
|
|
|
|
| 95 |
with gr.Tabs():
|
| 96 |
# --- Analysis Tab ---
|
| 97 |
with gr.TabItem("Analysis"):
|
| 98 |
+
with gr.Column(elem_classes="block-section"):
|
| 99 |
+
portfolio_input = gr.Textbox(
|
| 100 |
+
label="Portfolio ID or Link",
|
| 101 |
+
placeholder="Enter a portfolio ID (e.g. ea856c1b-...)",
|
| 102 |
+
lines=1,
|
| 103 |
+
value='b1ef37aa-5b9a-41b4-9394-8823f2de36bb',
|
| 104 |
+
)
|
| 105 |
+
analyze_button = gr.Button("Run Analysis", variant="primary")
|
| 106 |
+
analyze_output = gr.Textbox(
|
| 107 |
+
label="Analysis Result",
|
| 108 |
+
lines=15,
|
| 109 |
+
elem_id="analysis_output"
|
| 110 |
+
)
|
| 111 |
+
analyze_button.click(fn=analyzer.run, inputs=portfolio_input, outputs=analyze_output)
|
| 112 |
|
| 113 |
# --- Comparison Table Tab ---
|
| 114 |
with gr.TabItem("Comparison Table"):
|
| 115 |
+
with gr.Column(elem_classes="block-section"):
|
| 116 |
+
comp_input_1 = gr.Textbox(label="Portfolio A", value="3852a354-e66e-4bc5-97e9-55124e31e687")
|
| 117 |
+
comp_input_2 = gr.Textbox(label="Portfolio B", value="b1ef37aa-5b9a-41b4-9394-8823f2de36bb")
|
| 118 |
+
comp_button = gr.Button("Load Comparison", variant="primary")
|
| 119 |
+
|
| 120 |
+
comp_output_comment = gr.Textbox(
|
| 121 |
+
label="AI Commentary",
|
| 122 |
+
lines=8,
|
| 123 |
+
interactive=True,
|
| 124 |
+
show_copy_button=True,
|
| 125 |
+
elem_id="llm_comment_box",
|
| 126 |
+
)
|
| 127 |
+
|
| 128 |
+
comp_output_table = gr.Dataframe(
|
| 129 |
+
label="Comparative Metrics",
|
| 130 |
+
wrap=True,
|
| 131 |
+
elem_id="comparison_table",
|
| 132 |
+
)
|
| 133 |
+
|
| 134 |
+
comp_button.click(
|
| 135 |
+
fn=show_comparison_table,
|
| 136 |
+
inputs=[comp_input_1, comp_input_2],
|
| 137 |
+
outputs=[comp_output_table, comp_output_comment],
|
| 138 |
+
)
|
|
|
|
|
|
|
| 139 |
|
| 140 |
# --- Chat Assistant Tab ---
|
| 141 |
with gr.TabItem("Assistant"):
|
| 142 |
+
with gr.Column(elem_classes="block-section"):
|
| 143 |
+
chat_input = gr.Textbox(label="Ask about investments or analysis")
|
| 144 |
+
chat_button = gr.Button("Send Question", variant="primary")
|
| 145 |
+
chat_output = gr.Textbox(label="AI Response", lines=8, elem_id="chat_output")
|
| 146 |
+
chat_button.click(fn=chatbot.run, inputs=chat_input, outputs=chat_output)
|
| 147 |
|
| 148 |
# --- Metrics Table Tab ---
|
| 149 |
with gr.TabItem("Metrics Table"):
|
| 150 |
+
with gr.Column(elem_classes="block-section"):
|
| 151 |
+
metrics_input = gr.Textbox(label="Portfolio ID", value='b1ef37aa-5b9a-41b4-9394-8823f2de36bb')
|
| 152 |
+
metrics_button = gr.Button("Load Metrics", variant="primary")
|
| 153 |
+
metrics_output = gr.Dataframe(label="Portfolio Metrics", wrap=True)
|
| 154 |
+
metrics_button.click(fn=show_metrics_table, inputs=metrics_input, outputs=metrics_output)
|
| 155 |
|
| 156 |
+
# --- AlphaBTC Chart Tab ---
|
| 157 |
with gr.TabItem("AlphaBTC Chart"):
|
| 158 |
+
with gr.Column(elem_classes="block-section"):
|
| 159 |
+
chart_input = gr.Textbox(label="Portfolio ID", value="3852a354-e66e-4bc5-97e9-55124e31e687")
|
| 160 |
+
chart_button = gr.Button("Generate Chart", variant="primary")
|
| 161 |
+
chart_output = gr.Plot(label="Alpha vs BTC", show_label=False, elem_id="alpha_chart")
|
| 162 |
+
chart_button.click(fn=build_alpha_chart, inputs=chart_input, outputs=chart_output)
|
|
|
|
|
|
|
|
|
|
| 163 |
|
| 164 |
gr.Markdown("---")
|
| 165 |
gr.Markdown(
|
| 166 |
+
"<center><small>Developed with Featherless.ai • Powered by OpenAI-compatible API</small></center>",
|
| 167 |
elem_classes="footer",
|
| 168 |
)
|
| 169 |
|