Spaces:
Sleeping
Sleeping
| # app.py | |
| import gradio as gr | |
| from core.visits import get_and_update_visits | |
| from ui.layouts import create_ui | |
| # --- ✨ 1. Define a new custom theme for better aesthetics --- | |
| custom_theme = gr.themes.Soft( | |
| primary_hue="blue", | |
| secondary_hue="cyan", | |
| neutral_hue="slate", | |
| spacing_size=gr.themes.sizes.spacing_md, | |
| radius_size=gr.themes.sizes.radius_md, | |
| ).set( | |
| # Custom colors | |
| body_background_fill="#F0F4F8", # A light blue-gray for the main background | |
| block_background_fill="white", # White background for components | |
| block_border_width="1px", # Thin border for components | |
| block_shadow="*shadow_drop_lg", # Soft shadow for a floating effect | |
| # Custom button style | |
| button_primary_background_fill="*primary_500", | |
| button_primary_background_fill_hover="*primary_400", | |
| button_primary_text_color="white", | |
| ) | |
| # --- 2. Update site visit count on startup --- | |
| try: | |
| count = get_and_update_visits() | |
| visit_count_html = f"🚀 **總載入次數:** {count}" | |
| print(f"Application loaded. Total visits: {count}") | |
| except Exception as e: | |
| visit_count_html = "🚀 **總載入次數:** N/A" | |
| print(f"Could not update visit count: {e}") | |
| # --- 3. Create the main UI, passing both dynamic content and the new theme --- | |
| demo = create_ui(visit_count_html, theme=custom_theme) | |
| # --- 4. Launch the application --- | |
| if __name__ == "__main__": | |
| demo.launch() |