pentarosarium commited on
Commit
46fe2a8
·
1 Parent(s): 723da90
Files changed (1) hide show
  1. app.py +36 -74
app.py CHANGED
@@ -499,39 +499,7 @@ class ProcessingUI:
499
 
500
  with tab4:
501
  self.setup_analytics_tab()
502
-
503
- def setup_main_metrics_tab(self):
504
- """Setup the main metrics display"""
505
- # Create metrics containers
506
- metrics_cols = st.columns(4)
507
- self.total_processed = metrics_cols[0].empty()
508
- self.negative_count = metrics_cols[1].empty()
509
- self.events_count = metrics_cols[2].empty()
510
- self.speed_metric = metrics_cols[3].empty()
511
-
512
- # Recent items container with custom styling
513
- st.markdown("""
514
- <style>
515
- .recent-item {
516
- padding: 10px;
517
- margin: 5px 0;
518
- border-radius: 5px;
519
- background-color: #f0f2f6;
520
- }
521
- .negative-item {
522
- border-left: 4px solid #FF6B6B;
523
- }
524
- .positive-item {
525
- border-left: 4px solid #4ECDC4;
526
- }
527
- .event-item {
528
- border-left: 4px solid #FFE66D;
529
- }
530
- </style>
531
- """, unsafe_allow_html=True)
532
-
533
- self.recent_items_container = st.empty()
534
-
535
  def setup_entity_tab(self):
536
  """Setup the entity-wise analysis display"""
537
  # Entity filter
@@ -646,7 +614,7 @@ class ProcessingUI:
646
  self._update_recent_items(row, sentiment, event_type)
647
 
648
  def _update_recent_items(self, row, sentiment, event_type):
649
- """Update recent items display with custom styling"""
650
  if 'recent_items' not in st.session_state:
651
  st.session_state.recent_items = []
652
 
@@ -661,46 +629,40 @@ class ProcessingUI:
661
 
662
  st.session_state.recent_items.insert(0, new_item)
663
  st.session_state.recent_items = st.session_state.recent_items[:10] # Keep last 10 items
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
664
 
665
- # Create combined markdown for all items
666
- all_items_markdown = ""
667
- for item in st.session_state.recent_items:
668
- if item['sentiment'] in ['Positive', 'Negative']:
669
- # Create color based on sentiment
670
- color = "#FF6B6B" if item['sentiment'] == 'Negative' else "#4ECDC4"
671
-
672
- # Add item markdown
673
- all_items_markdown += f"""
674
- <div style='
675
- padding: 10px;
676
- margin-bottom: 10px;
677
- border-radius: 4px;
678
- background-color: #f8f9fa;
679
- border-left: 4px solid {color};
680
- '>
681
- <div style='font-weight: bold;'>{item['entity']}</div>
682
- <div style='margin: 5px 0;'>{item['headline']}</div>
683
- <div style='font-size: 0.9em; color: #666;'>
684
- Тональность: {item['sentiment']}
685
- {f" | Событие: {item['event_type']}" if item['event_type'] != 'Нет' else ""}
686
- | {item['time']}
687
- </div>
688
- </div>
689
- """
690
-
691
- # Add wrapper for scrolling
692
- final_markdown = f"""
693
- <div style='
694
- max-height: 400px;
695
- overflow-y: auto;
696
- padding-right: 10px;
697
- '>
698
- {all_items_markdown}
699
- </div>
700
- """
701
-
702
- # Update the container with all items at once
703
- self.recent_items_container.markdown(final_markdown, unsafe_allow_html=True)
704
 
705
  def _update_entity_view(self):
706
  """Update entity tab visualizations"""
@@ -1597,7 +1559,7 @@ def main():
1597
  st.set_page_config(layout="wide")
1598
 
1599
  with st.sidebar:
1600
- st.title("::: AI-анализ мониторинга новостей (v.4.1):::")
1601
  st.subheader("по материалам СКАН-ИНТЕРФАКС")
1602
 
1603
  model_choice = st.radio(
 
499
 
500
  with tab4:
501
  self.setup_analytics_tab()
502
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
503
  def setup_entity_tab(self):
504
  """Setup the entity-wise analysis display"""
505
  # Entity filter
 
614
  self._update_recent_items(row, sentiment, event_type)
615
 
616
  def _update_recent_items(self, row, sentiment, event_type):
617
+ """Update recent items display using Streamlit native components"""
618
  if 'recent_items' not in st.session_state:
619
  st.session_state.recent_items = []
620
 
 
629
 
630
  st.session_state.recent_items.insert(0, new_item)
631
  st.session_state.recent_items = st.session_state.recent_items[:10] # Keep last 10 items
632
+
633
+ # Display items using Streamlit components
634
+ with self.recent_items_container:
635
+ for item in st.session_state.recent_items:
636
+ if item['sentiment'] in ['Positive', 'Negative']:
637
+ # Use different background colors for different sentiments
638
+ background_color = "#ffebee" if item['sentiment'] == 'Negative' else "#e8f5e9"
639
+
640
+ # Create container for each item
641
+ with st.container():
642
+ st.markdown("""---""") # Separator
643
+ # Entity name in bold
644
+ st.markdown(f"**{item['entity']}**")
645
+ # Headline
646
+ st.write(item['headline'])
647
+ # Metadata row
648
+ meta = f"_{item['sentiment']}"
649
+ if item['event_type'] != 'Нет':
650
+ meta += f" | Событие: {item['event_type']}"
651
+ meta += f" | {item['time']}_"
652
+ st.markdown(meta)
653
+
654
+ def setup_main_metrics_tab(self):
655
+ """Setup the main metrics display with updated styling"""
656
+ # Create metrics containers
657
+ metrics_cols = st.columns(4)
658
+ self.total_processed = metrics_cols[0].empty()
659
+ self.negative_count = metrics_cols[1].empty()
660
+ self.events_count = metrics_cols[2].empty()
661
+ self.speed_metric = metrics_cols[3].empty()
662
 
663
+ # Recent items container
664
+ st.markdown("### Последние новости:")
665
+ self.recent_items_container = st.container()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
666
 
667
  def _update_entity_view(self):
668
  """Update entity tab visualizations"""
 
1559
  st.set_page_config(layout="wide")
1560
 
1561
  with st.sidebar:
1562
+ st.title("::: AI-анализ мониторинга новостей (v.4.2):::")
1563
  st.subheader("по материалам СКАН-ИНТЕРФАКС")
1564
 
1565
  model_choice = st.radio(