Spaces:
Sleeping
Sleeping
Upload app_simplified.py with huggingface_hub
Browse files- 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 |
-
|
| 702 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 703 |
|
| 704 |
-
|
| 705 |
-
|
|
|
|
|
|
|
| 706 |
|
| 707 |
-
|
| 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
|
| 715 |
|
| 716 |
with col2:
|
| 717 |
-
st.metric("β Failed APIs", summary
|
| 718 |
|
| 719 |
with col3:
|
| 720 |
-
st.metric("π Success Rate", f"{summary
|
| 721 |
|
| 722 |
with col4:
|
| 723 |
-
|
| 724 |
-
|
|
|
|
|
|
|
|
|
|
| 725 |
|
| 726 |
-
# Detailed results
|
| 727 |
st.markdown("### π Detailed Results")
|
| 728 |
|
| 729 |
-
|
| 730 |
-
with st.
|
| 731 |
-
|
| 732 |
-
|
| 733 |
-
|
| 734 |
-
|
| 735 |
-
|
| 736 |
-
|
| 737 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 754 |
-
|
| 755 |
-
|
| 756 |
-
|
| 757 |
-
|
| 758 |
-
|
| 759 |
-
|
| 760 |
-
|
| 761 |
-
|
| 762 |
-
|
| 763 |
-
|
| 764 |
-
|
| 765 |
-
|
| 766 |
-
|
| 767 |
-
|
| 768 |
-
|
| 769 |
-
|
| 770 |
-
|
| 771 |
-
|
| 772 |
-
|
| 773 |
-
|
| 774 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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"):
|