CosmickVisions commited on
Commit
d35bbe4
Β·
verified Β·
1 Parent(s): eca6d25

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -214
app.py CHANGED
@@ -54,53 +54,10 @@ chart_data_store = {}
54
 
55
  # Custom CSS for Finance theme with modern UI enhancements
56
  custom_css = """
57
- :root {
58
- --main-bg: #ffffff;
59
- --main-text: #000000;
60
- --accent-primary: #2563eb; // Bold blue
61
- --accent-secondary: #dc2626; // Red for alerts
62
- --accent-tertiary: #eab308; // Yellow for highlights
63
- --border-color: #e5e7eb;
64
- --radius-md: 8px;
65
- --spacing-sm: 8px;
66
- --spacing-md: 16px;
67
- --spacing-lg: 24px;
68
- --shadow-sm: 0 1px 3px rgba(0,0,0,0.12);
69
- --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
70
- --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
71
- }
72
-
73
- /* Chat Interface Styling */
74
- .chat-container {
75
- background: var(--main-bg);
76
- border-radius: var(--radius-md);
77
- border: 1px solid var(--border-color);
78
- padding: var(--spacing-md);
79
- margin-bottom: var(--spacing-md);
80
- }
81
-
82
- .message {
83
- padding: 12px 16px;
84
- border-radius: 8px;
85
- margin: 8px 0;
86
- max-width: 80%;
87
- }
88
-
89
- .user-message {
90
- background: #f0f4ff;
91
- margin-left: auto;
92
- border: 1px solid #d6e0ff;
93
- }
94
-
95
- .bot-message {
96
- background: #fff;
97
- margin-right: auto;
98
- border: 1px solid #e0e0e0;
99
- }
100
-
101
  /* Finance-specific styles */
102
  .finance-card {
103
- background: #f8fafc;
104
  border: 1px solid var(--border-color);
105
  border-radius: var(--radius-md);
106
  padding: var(--spacing-lg);
@@ -108,187 +65,45 @@ custom_css = """
108
  box-shadow: var(--shadow-md);
109
  transition: transform 0.3s, box-shadow 0.3s;
110
  }
111
-
112
- .header {
113
- text-align: center;
114
- padding: var(--spacing-lg) 0;
115
- border-bottom: 1px solid var(--border-color);
116
- margin-bottom: var(--spacing-lg);
117
- }
118
-
119
- .header-title {
120
- font-size: 1.5rem;
121
- font-weight: 600;
122
- color: var(--main-text);
123
- display: flex;
124
- align-items: center;
125
- justify-content: center;
126
- gap: 8px;
127
- }
128
-
129
- .badge {
130
- font-size: 0.7em;
131
- padding: 2px 8px;
132
- border-radius: 12px;
133
- background: var(--accent-primary);
134
- color: white;
135
- }
136
-
137
  .finance-card:hover {
138
  transform: translateY(-5px);
139
  box-shadow: var(--shadow-lg);
140
- border-color: var(--accent-primary);
141
  }
142
-
143
  .chart-container {
144
- background: var(--main-bg);
145
  border-radius: var(--radius-md);
146
  padding: var(--spacing-md);
147
  margin: var(--spacing-md) 0;
148
  box-shadow: var(--shadow-sm);
149
  }
150
-
151
  .news-feed {
152
  max-height: 400px;
153
  overflow-y: auto;
154
  padding: var(--spacing-md);
155
  border: 1px solid var(--border-color);
156
  border-radius: var(--radius-md);
157
- background: var(--main-bg);
158
  }
159
-
160
  .news-item {
161
  margin-bottom: var(--spacing-md);
162
  padding-bottom: var(--spacing-md);
163
  border-bottom: 1px solid var(--border-color);
164
  }
165
-
166
  .news-title {
167
  font-size: 1.1rem;
168
  font-weight: 600;
169
- color: var(--main-text);
170
  margin-bottom: var(--spacing-sm);
171
  }
172
-
173
  .news-summary {
174
- color: var(--main-text-secondary);
175
  line-height: 1.6;
176
  }
177
-
178
  .sentiment-gauge {
179
  width: 100%;
180
  height: 200px;
181
  margin: var(--spacing-md) 0;
182
  }
183
-
184
- /* Modern Financial Dashboard Styles */
185
- .dashboard-grid {
186
- display: grid;
187
- gap: 1.5rem;
188
- grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
189
- }
190
-
191
- .ticker-tape {
192
- background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
193
- color: white;
194
- padding: 1rem;
195
- border-radius: var(--radius-md);
196
- overflow: hidden;
197
- position: relative;
198
- }
199
-
200
- .stock-card {
201
- background: white;
202
- border-radius: var(--radius-md);
203
- padding: 1.5rem;
204
- transition: transform 0.3s ease;
205
- cursor: pointer;
206
- position: relative;
207
- overflow: hidden;
208
- }
209
-
210
- .stock-card::before {
211
- content: '';
212
- position: absolute;
213
- top: -50%;
214
- left: -50%;
215
- width: 200%;
216
- height: 200%;
217
- background: linear-gradient(45deg, transparent, rgba(255,255,255,0.1));
218
- transform: rotate(45deg);
219
- transition: all 0.5s ease;
220
- }
221
-
222
- .stock-card:hover {
223
- transform: translateY(-5px);
224
- box-shadow: 0 10px 20px rgba(0,0,0,0.1);
225
- }
226
-
227
- .stock-card:hover::before {
228
- transform: rotate(45deg) translateX(50%);
229
- }
230
-
231
- .realtime-chart {
232
- border: 1px solid var(--border-color);
233
- border-radius: var(--radius-md);
234
- padding: 1rem;
235
- background: white;
236
- position: relative;
237
- }
238
-
239
- .chart-tooltip {
240
- position: absolute;
241
- background: var(--main-text);
242
- color: var(--main-bg);
243
- padding: 0.5rem 1rem;
244
- border-radius: var(--radius-sm);
245
- pointer-events: none;
246
- opacity: 0;
247
- transition: opacity 0.2s ease;
248
- }
249
-
250
- .dark-mode .ticker-tape {
251
- background: linear-gradient(90deg, #1e3a8a, #991b1b) !important;
252
- }
253
-
254
- .dark-mode .stock-card {
255
- background: #2d2d2d !important;
256
- }
257
- """
258
-
259
- # Add JavaScript interactions
260
- financial_js = """
261
- <script>
262
- document.addEventListener('DOMContentLoaded', () => {
263
- // Real-time chart interactions
264
- const charts = document.querySelectorAll('.realtime-chart');
265
- charts.forEach(chart => {
266
- chart.addEventListener('mousemove', (e) => {
267
- const tooltip = chart.querySelector('.chart-tooltip');
268
- if(tooltip) {
269
- tooltip.style.left = `${e.offsetX + 10}px`;
270
- tooltip.style.top = `${e.offsetY + 10}px`;
271
- tooltip.style.opacity = '1';
272
- }
273
- });
274
-
275
- chart.addEventListener('mouseleave', () => {
276
- const tooltip = chart.querySelector('.chart-tooltip');
277
- if(tooltip) tooltip.style.opacity = '0';
278
- });
279
- });
280
-
281
- // Animated ticker tape
282
- const ticker = document.querySelector('.ticker-tape');
283
- if(ticker) {
284
- let position = 0;
285
- setInterval(() => {
286
- position -= 1;
287
- ticker.style.backgroundPosition = `${position}px 0`;
288
- }, 50);
289
- }
290
- });
291
- </script>
292
  """
293
 
294
  # Function to process PDF files
@@ -883,7 +698,6 @@ def analyze_ticker(ticker_input, period, use_brave_search=False):
883
  search_provider = "Brave Search" if (use_brave_search and BRAVE_API_KEY) else "Serper" if SERPER_API_KEY else "AI Knowledge Base"
884
  summary = f"""
885
  ### {ticker} Analysis (Using {search_provider})
886
-
887
  **Current Price:** ${stock_data['current_price']}
888
  **52-Week High:** ${stock_data['52wk_high']}
889
  **Market Cap:** ${stock_data['market_cap']:,}
@@ -892,7 +706,6 @@ def analyze_ticker(ticker_input, period, use_brave_search=False):
892
  **Beta:** {stock_data['beta']}
893
  **Avg Volume:** {stock_data['average_volume']:,}
894
  {sentiment_summary}
895
-
896
  For in-depth analysis of this chart, ask the chatbot by typing "/chart" or "/analyze chart".
897
  For latest news, type "/news {ticker}".
898
  """
@@ -916,17 +729,14 @@ def analyze_image(image_file):
916
  mode = image.mode
917
 
918
  analysis = f"""## Technical Document Analysis
919
-
920
  **Image Properties:**
921
  - Dimensions: {width}x{height} pixels
922
  - Format: {format}
923
  - Color Mode: {mode}
924
-
925
  **Technical Analysis:**
926
  1. Document Quality:
927
  - Resolution: {'High' if width > 2000 or height > 2000 else 'Medium' if width > 1000 or height > 1000 else 'Low'}
928
  - Color Depth: {mode}
929
-
930
  2. Recommendations:
931
  - For text extraction, consider using PDF format
932
  - For technical diagrams, ensure high resolution
@@ -946,10 +756,8 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
946
 
947
  gr.HTML("""
948
  <div class="header">
949
- <div class="header-title">πŸ’° Fin-Vision AI
950
- <span class="badge">Beta</span>
951
- </div>
952
- <div class="header-subtitle">Financial Analysis Copilot</div>
953
  </div>
954
  """)
955
 
@@ -957,27 +765,35 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
957
  with gr.Tabs() as main_tabs:
958
  # Chat Assistant Tab
959
  with gr.TabItem("πŸ’¬ Chat Assistant", id=0):
 
 
 
 
 
 
 
 
 
 
 
 
 
960
  chatbot = gr.Chatbot(
961
  height=600,
962
  show_copy_button=True,
963
  elem_classes="chat-container",
964
  container=True,
965
- type="messages",
966
- avatar_images=(
967
- "assets/user.png",
968
- "assets/bot_finance.png"
969
- )
970
  )
 
971
  with gr.Row():
972
  msg = gr.Textbox(
973
  show_label=False,
974
- placeholder="πŸ’¬ Ask about markets, type /news for updates, /chart for analysis...",
975
- scale=8,
976
- container=False
977
  )
978
- with gr.Column(scale=1):
979
- send_btn = gr.Button("Send", variant="primary")
980
- clear_btn = gr.Button("πŸ”„ Clear", variant="secondary")
981
 
982
  # Document Analysis Tab
983
  with gr.TabItem("πŸ“„ Document Analysis", id=1):
@@ -1008,7 +824,7 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
1008
  with gr.TabItem("πŸ” Financial Tools", id=2):
1009
  with gr.Tabs() as financial_tabs:
1010
  # Stock Analysis
1011
- with gr.TabItem("πŸ“ˆ Stock Analysis"):
1012
  with gr.Row():
1013
  with gr.Column():
1014
  ticker_input = gr.Textbox(
@@ -1026,7 +842,7 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
1026
  stock_analysis = gr.Markdown()
1027
 
1028
  # Market News
1029
- with gr.TabItem("πŸ“° Market News"):
1030
  news_ticker = gr.Textbox(
1031
  label="Company/Ticker",
1032
  placeholder="Enter company name or ticker symbol"
@@ -1035,7 +851,7 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
1035
  news_results = gr.Markdown()
1036
 
1037
  # Financial Report Analysis
1038
- with gr.TabItem("πŸ–ΌοΈ Report Analysis"):
1039
  with gr.Row():
1040
  with gr.Column():
1041
  report_image = gr.File(
 
54
 
55
  # Custom CSS for Finance theme with modern UI enhancements
56
  custom_css = """
57
+ @import url('shared-base.css');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  /* Finance-specific styles */
59
  .finance-card {
60
+ background: var(--surface-2);
61
  border: 1px solid var(--border-color);
62
  border-radius: var(--radius-md);
63
  padding: var(--spacing-lg);
 
65
  box-shadow: var(--shadow-md);
66
  transition: transform 0.3s, box-shadow 0.3s;
67
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  .finance-card:hover {
69
  transform: translateY(-5px);
70
  box-shadow: var(--shadow-lg);
 
71
  }
 
72
  .chart-container {
73
+ background: var(--white);
74
  border-radius: var(--radius-md);
75
  padding: var(--spacing-md);
76
  margin: var(--spacing-md) 0;
77
  box-shadow: var(--shadow-sm);
78
  }
 
79
  .news-feed {
80
  max-height: 400px;
81
  overflow-y: auto;
82
  padding: var(--spacing-md);
83
  border: 1px solid var(--border-color);
84
  border-radius: var(--radius-md);
85
+ background: var(--surface-1);
86
  }
 
87
  .news-item {
88
  margin-bottom: var(--spacing-md);
89
  padding-bottom: var(--spacing-md);
90
  border-bottom: 1px solid var(--border-color);
91
  }
 
92
  .news-title {
93
  font-size: 1.1rem;
94
  font-weight: 600;
95
+ color: var(--text-color);
96
  margin-bottom: var(--spacing-sm);
97
  }
 
98
  .news-summary {
99
+ color: var(--text-color-secondary);
100
  line-height: 1.6;
101
  }
 
102
  .sentiment-gauge {
103
  width: 100%;
104
  height: 200px;
105
  margin: var(--spacing-md) 0;
106
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  """
108
 
109
  # Function to process PDF files
 
698
  search_provider = "Brave Search" if (use_brave_search and BRAVE_API_KEY) else "Serper" if SERPER_API_KEY else "AI Knowledge Base"
699
  summary = f"""
700
  ### {ticker} Analysis (Using {search_provider})
 
701
  **Current Price:** ${stock_data['current_price']}
702
  **52-Week High:** ${stock_data['52wk_high']}
703
  **Market Cap:** ${stock_data['market_cap']:,}
 
706
  **Beta:** {stock_data['beta']}
707
  **Avg Volume:** {stock_data['average_volume']:,}
708
  {sentiment_summary}
 
709
  For in-depth analysis of this chart, ask the chatbot by typing "/chart" or "/analyze chart".
710
  For latest news, type "/news {ticker}".
711
  """
 
729
  mode = image.mode
730
 
731
  analysis = f"""## Technical Document Analysis
 
732
  **Image Properties:**
733
  - Dimensions: {width}x{height} pixels
734
  - Format: {format}
735
  - Color Mode: {mode}
 
736
  **Technical Analysis:**
737
  1. Document Quality:
738
  - Resolution: {'High' if width > 2000 or height > 2000 else 'Medium' if width > 1000 or height > 1000 else 'Low'}
739
  - Color Depth: {mode}
 
740
  2. Recommendations:
741
  - For text extraction, consider using PDF format
742
  - For technical diagrams, ensure high resolution
 
756
 
757
  gr.HTML("""
758
  <div class="header">
759
+ <div class="header-title">Fin-Vision AI</div>
760
+ <div class="header-subtitle">Advanced Financial Analysis Assistant</div>
 
 
761
  </div>
762
  """)
763
 
 
765
  with gr.Tabs() as main_tabs:
766
  # Chat Assistant Tab
767
  with gr.TabItem("πŸ’¬ Chat Assistant", id=0):
768
+ with gr.Row():
769
+ with gr.Column(scale=1):
770
+ model_dropdown = gr.Dropdown(
771
+ choices=["llama3-70b-8192", "llama3-8b-8192", "mixtral-8x7b-32768", "gemma-7b-it"],
772
+ value="llama3-70b-8192",
773
+ label="Model Selection"
774
+ )
775
+ web_search_toggle = gr.Checkbox(
776
+ label="Enable Financial Search",
777
+ value=True,
778
+ info="Toggle web search functionality"
779
+ )
780
+
781
  chatbot = gr.Chatbot(
782
  height=600,
783
  show_copy_button=True,
784
  elem_classes="chat-container",
785
  container=True,
786
+ type="messages"
 
 
 
 
787
  )
788
+
789
  with gr.Row():
790
  msg = gr.Textbox(
791
  show_label=False,
792
+ placeholder="Ask about financial markets, analyze stocks, or discuss financial documents...",
793
+ scale=8
 
794
  )
795
+ send_btn = gr.Button("Send", scale=1)
796
+ clear_btn = gr.Button("Clear Conversation")
 
797
 
798
  # Document Analysis Tab
799
  with gr.TabItem("πŸ“„ Document Analysis", id=1):
 
824
  with gr.TabItem("πŸ” Financial Tools", id=2):
825
  with gr.Tabs() as financial_tabs:
826
  # Stock Analysis
827
+ with gr.TabItem("Stock Analysis"):
828
  with gr.Row():
829
  with gr.Column():
830
  ticker_input = gr.Textbox(
 
842
  stock_analysis = gr.Markdown()
843
 
844
  # Market News
845
+ with gr.TabItem("Market News"):
846
  news_ticker = gr.Textbox(
847
  label="Company/Ticker",
848
  placeholder="Enter company name or ticker symbol"
 
851
  news_results = gr.Markdown()
852
 
853
  # Financial Report Analysis
854
+ with gr.TabItem("Report Analysis"):
855
  with gr.Row():
856
  with gr.Column():
857
  report_image = gr.File(