import gradio as gr import pandas as pd # Custom CSS for enhanced styling custom_css = """ footer {visibility: hidden} .app-title { text-align: center; color: #2F4F4F; font-size: 2em !important; font-weight: 500; margin-bottom: 0.5em !important; text-transform: lowercase; } .logo-container { text-align: center; margin-bottom: 1em; } .logo-img { width: 200px; height: auto; margin: 0 auto; display: block; } .filter-section { background: #f8f9fa; padding: 20px; border-radius: 12px; margin-bottom: 2em; box-shadow: 0 2px 8px rgba(0,0,0,0.1); } .results-section { margin-top: 2em; } .dataframe { border-radius: 8px !important; overflow: hidden !important; box-shadow: 0 4px 6px rgba(0,0,0,0.05) !important; } .button-primary { background: linear-gradient(45deg, #4B0082, #6A5ACD) !important; color: white !important; border: none !important; padding: 12px 24px !important; border-radius: 8px !important; transition: transform 0.2s ease !important; } .button-primary:hover { transform: translateY(-1px); } .button-secondary { background: linear-gradient(45deg, #228B22, #32CD32) !important; border: none !important; } .empty-state { text-align: center; padding: 40px 20px; background: #f8f9fa; border-radius: 12px; margin: 2em 0; color: #666; } .footer-text { text-align: center; color: #666; margin-top: 2em !important; font-style: italic; } """ # Load the Excel file data = pd.read_excel('Indigenous Business Directory by Gov of Canada.xlsx') # Updated service types service_types = ["All", "Electrical", "Mechanical", "HVAC", "Sprinkler", "Plumbing", "Demo", "Paint", "Millwork", "Flooring", "Drywall/Framing", "Concrete/Scanning", "Excavation", "Steel"] def update_city_options(province): if not province: return gr.Dropdown(choices=[], label="Select City", multiselect=True) cities = ["All"] + data[data['Province'] == province]['City'].unique().tolist() return gr.Dropdown(choices=cities, label="Select City", multiselect=True) def search_directory(province, cities, service_types): if not province: return pd.DataFrame(columns=["Company Name", "Mail", "Website", "Phone", "Fax", "Address"]) filtered_data = data[data['Province'] == province] if cities and "All" not in cities: filtered_data = filtered_data[filtered_data['City'].isin(cities)] if service_types and "All" not in service_types: service_filter = filtered_data['Company Description'].apply( lambda desc: any(service.lower() in str(desc).lower() for service in service_types) ) filtered_data = filtered_data[service_filter] if filtered_data.empty: return pd.DataFrame(columns=["Company Name", "Mail", "Website", "Phone", "Fax", "Address"]) filtered_data['Address'] = ( filtered_data['Address 1'].astype(str) + ", " + filtered_data['City'].astype(str) + ", " + filtered_data['Province'].astype(str) ) result_df = filtered_data.rename( columns={ 'Company Operating Name': 'Company Name', 'Email': 'Mail', 'URL': 'Website', 'Phone Number': 'Phone', 'Fax Number': 'Fax' } )[['Company Name', 'Mail', 'Website', 'Phone', 'Fax', 'Address']] return result_df def export_results_to_excel(province, cities, service_types): results_df = search_directory(province, cities, service_types) if results_df.empty: raise gr.Error("No results to export!") cities = cities or [] service_types = service_types or [] filename = f"Search_Results_{province}_{'_'.join(map(str, cities))}_{'_'.join(map(str, service_types))}.xlsx" results_df.to_excel(filename, index=False) return filename with gr.Blocks( theme=gr.themes.Default( primary_hue="indigo", secondary_hue="emerald", neutral_hue="slate", radius_size="md", text_size="md" ), css=custom_css ) as app: # Header Section gr.HTML("""
Try adjusting your filters or search criteria