isakskogstad commited on
Commit
1281e4d
Β·
verified Β·
1 Parent(s): 68745c6

Upload app_simplified.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app_simplified.py +113 -44
app_simplified.py CHANGED
@@ -698,43 +698,84 @@ with col2:
698
 
699
  # Execute the one-click data collection
700
  with st.spinner("πŸ”„ Collecting data from all APIs..."):
701
- results = st.session_state.harvester.fetch_all_apis(update_progress)
702
- st.session_state.last_results = results
 
 
 
 
 
 
 
 
 
 
703
 
704
- progress_bar.progress(1.0)
705
- status_container.text("βœ… Collection completed!")
 
 
706
 
707
- # Show results
708
- summary = results['summary']
709
 
710
  # Success metrics
711
  col1, col2, col3, col4 = st.columns(4)
712
 
713
  with col1:
714
- st.metric("βœ… Successful APIs", summary['successful'])
715
 
716
  with col2:
717
- st.metric("❌ Failed APIs", summary['failed'])
718
 
719
  with col3:
720
- st.metric("πŸ“Š Success Rate", f"{summary['success_rate']:.1f}%")
721
 
722
  with col4:
723
- total_records = sum(api_data['total_records'] for api_data in results['results'].values())
724
- st.metric("πŸ“„ Total Records", f"{total_records:,}")
 
 
 
725
 
726
- # Detailed results
727
  st.markdown("### πŸ“‹ Detailed Results")
728
 
729
- for api_name, api_data in results['results'].items():
730
- with st.expander(f"βœ… {SIMPLIFIED_API_CONFIG[api_name]['name']} - {api_data['total_records']} records"):
731
- for endpoint in api_data['endpoints']:
732
- st.write(f"**URL:** {endpoint['endpoint_url']}")
733
- st.write(f"**Records:** {endpoint['records']} | **Duration:** {endpoint['duration_ms']}ms | **Size:** {endpoint['size_bytes']} bytes")
734
-
735
- if endpoint.get('data_preview'):
736
- st.write("**Data Preview:**")
737
- st.code(endpoint['data_preview'], language="json")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
738
 
739
  # Error details
740
  if results['errors']:
@@ -749,29 +790,57 @@ if st.session_state.last_results:
749
 
750
  results = st.session_state.last_results
751
 
752
- # Create simple visualizations
753
- if results['results']:
754
- # API success chart
755
- api_names = []
756
- record_counts = []
757
-
758
- for api_name, api_data in results['results'].items():
759
- api_names.append(SIMPLIFIED_API_CONFIG[api_name]['name'])
760
- record_counts.append(api_data['total_records'])
761
-
762
- if record_counts and any(count > 0 for count in record_counts):
763
- fig = px.bar(
764
- x=api_names,
765
- y=record_counts,
766
- title="πŸ“Š Records Collected by API",
767
- labels={'x': 'API', 'y': 'Records'}
768
- )
769
- fig.update_layout(
770
- paper_bgcolor="rgba(255,255,255,0.9)",
771
- plot_bgcolor="rgba(255,255,255,0.9)",
772
- font_color="#2c3e50"
773
- )
774
- st.plotly_chart(fig, use_container_width=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
775
 
776
  # Enhanced Database viewer
777
  with st.expander("πŸ—„οΈ Enhanced Database Viewer"):
 
698
 
699
  # Execute the one-click data collection
700
  with st.spinner("πŸ”„ Collecting data from all APIs..."):
701
+ try:
702
+ results = st.session_state.harvester.fetch_all_apis(update_progress)
703
+ st.session_state.last_results = results
704
+
705
+ progress_bar.progress(1.0)
706
+ status_container.success("βœ… Collection completed!")
707
+
708
+ except Exception as e:
709
+ progress_bar.progress(0.0)
710
+ status_container.error(f"❌ Collection failed: {str(e)}")
711
+ st.error("Data collection encountered an error. Please try again.")
712
+ st.stop() # Stop execution here if collection failed
713
 
714
+ # Show results only if collection was successful
715
+ if 'results' not in locals() or not results:
716
+ st.error("No results to display")
717
+ st.stop()
718
 
719
+ summary = results.get('summary', {})
 
720
 
721
  # Success metrics
722
  col1, col2, col3, col4 = st.columns(4)
723
 
724
  with col1:
725
+ st.metric("βœ… Successful APIs", summary.get('successful', 0))
726
 
727
  with col2:
728
+ st.metric("❌ Failed APIs", summary.get('failed', 0))
729
 
730
  with col3:
731
+ st.metric("πŸ“Š Success Rate", f"{summary.get('success_rate', 0):.1f}%")
732
 
733
  with col4:
734
+ try:
735
+ total_records = sum(api_data.get('total_records', 0) for api_data in results.get('results', {}).values())
736
+ st.metric("πŸ“„ Total Records", f"{total_records:,}")
737
+ except Exception:
738
+ st.metric("πŸ“„ Total Records", "Error")
739
 
740
+ # Detailed results with progress indicator
741
  st.markdown("### πŸ“‹ Detailed Results")
742
 
743
+ if len(results['results']) > 5:
744
+ with st.spinner("Loading detailed results..."):
745
+ time.sleep(0.1) # Small delay to show spinner
746
+
747
+ try:
748
+ # Limit to first 8 APIs to prevent UI overload
749
+ apis_to_show = list(results['results'].items())[:8]
750
+
751
+ for api_name, api_data in apis_to_show:
752
+ with st.expander(f"βœ… {SIMPLIFIED_API_CONFIG[api_name]['name']} - {api_data['total_records']} records"):
753
+ for endpoint in api_data['endpoints']:
754
+ col1, col2 = st.columns([3, 1])
755
+
756
+ with col1:
757
+ st.write(f"**URL:** {endpoint['endpoint_url']}")
758
+ st.write(f"**Records:** {endpoint['records']} | **Duration:** {endpoint['duration_ms']}ms | **Size:** {endpoint['size_bytes']} bytes")
759
+
760
+ with col2:
761
+ if endpoint.get('status') == 'success':
762
+ st.success("βœ… Success")
763
+ else:
764
+ st.error("❌ Failed")
765
+
766
+ # Show a very limited preview
767
+ if endpoint.get('data_preview') and len(str(endpoint.get('data_preview', ''))) > 10:
768
+ with st.container():
769
+ st.write("**Sample Data:**")
770
+ preview_text = str(endpoint.get('data_preview', ''))[:100]
771
+ st.code(preview_text + "..." if len(preview_text) == 100 else preview_text)
772
+
773
+ if len(results['results']) > 8:
774
+ st.info(f"Showing first 8 APIs. Total: {len(results['results'])} APIs processed successfully.")
775
+
776
+ except Exception as e:
777
+ st.error(f"Error displaying results: {str(e)}")
778
+ st.info("βœ… Data collection completed successfully! Check the database viewer below for stored data.")
779
 
780
  # Error details
781
  if results['errors']:
 
790
 
791
  results = st.session_state.last_results
792
 
793
+ # Create simple visualizations with error handling
794
+ try:
795
+ if results.get('results') and len(results['results']) > 0:
796
+ # Simple metrics display instead of complex charts
797
+ col1, col2, col3 = st.columns(3)
798
+
799
+ with col1:
800
+ total_apis = len(results['results'])
801
+ st.metric("🌍 APIs Processed", total_apis)
802
+
803
+ with col2:
804
+ total_records = sum(api_data.get('total_records', 0) for api_data in results['results'].values())
805
+ st.metric("πŸ“„ Total Records", f"{total_records:,}")
806
+
807
+ with col3:
808
+ total_size = sum(api_data.get('total_size', 0) for api_data in results['results'].values())
809
+ size_mb = total_size / (1024 * 1024)
810
+ st.metric("πŸ’Ύ Data Size", f"{size_mb:.2f} MB")
811
+
812
+ # Simple bar chart with limited data
813
+ if len(results['results']) <= 10: # Only show chart for reasonable number of APIs
814
+ api_names = []
815
+ record_counts = []
816
+
817
+ for api_name, api_data in list(results['results'].items())[:8]: # Limit to 8 APIs
818
+ api_names.append(SIMPLIFIED_API_CONFIG[api_name]['name'][:20]) # Truncate names
819
+ record_counts.append(api_data.get('total_records', 0))
820
+
821
+ if record_counts and any(count > 0 for count in record_counts):
822
+ try:
823
+ fig = px.bar(
824
+ x=api_names,
825
+ y=record_counts,
826
+ title="πŸ“Š Records by API (Top 8)",
827
+ labels={'x': 'API', 'y': 'Records'}
828
+ )
829
+ fig.update_layout(
830
+ paper_bgcolor="rgba(255,255,255,0.9)",
831
+ plot_bgcolor="rgba(255,255,255,0.9)",
832
+ font_color="#2c3e50",
833
+ height=400
834
+ )
835
+ st.plotly_chart(fig, use_container_width=True)
836
+ except Exception as chart_error:
837
+ st.info("Chart generation skipped due to data size")
838
+ else:
839
+ st.info("πŸ“Š Chart display skipped - too many APIs for optimal viewing")
840
+
841
+ except Exception as e:
842
+ st.warning("Analytics display skipped due to data processing complexity")
843
+ st.info("βœ… Data collection was successful - check database viewer below")
844
 
845
  # Enhanced Database viewer
846
  with st.expander("πŸ—„οΈ Enhanced Database Viewer"):