cwadayi commited on
Commit
744cd23
·
verified ·
1 Parent(s): 57b8366

Upload 8 files

Browse files
Files changed (2) hide show
  1. app.py +2 -6
  2. ui/layouts.py +10 -2
app.py CHANGED
@@ -1,5 +1,4 @@
1
  # app.py
2
- import gradio as gr
3
  from core.visits import get_and_update_visits
4
  from ui.layouts import create_ui
5
 
@@ -13,11 +12,8 @@ except Exception as e:
13
  visit_count_html = "🚀 **總載入次數:** N/A"
14
  print(f"Could not update visit count: {e}")
15
 
16
- # --- 2. Create the main UI ---
17
- # We insert the visit count HTML into the UI using a simple trick
18
- # by adding a Markdown component at the very top.
19
- demo = create_ui()
20
- demo.blocks.insert(0, gr.Markdown(visit_count_html)) # Insert the count at the top
21
 
22
  # --- 3. Launch the application ---
23
  if __name__ == "__main__":
 
1
  # app.py
 
2
  from core.visits import get_and_update_visits
3
  from ui.layouts import create_ui
4
 
 
12
  visit_count_html = "🚀 **總載入次數:** N/A"
13
  print(f"Could not update visit count: {e}")
14
 
15
+ # --- 2. Create the main UI by passing the dynamic content into the layout function ---
16
+ demo = create_ui(visit_count_html)
 
 
 
17
 
18
  # --- 3. Launch the application ---
19
  if __name__ == "__main__":
ui/layouts.py CHANGED
@@ -3,11 +3,19 @@ import gradio as gr
3
  from config import content, data, defaults
4
  from core import callbacks
5
 
6
- def create_ui():
7
- """Creates and returns the Gradio UI Blocks."""
 
 
 
 
 
8
 
9
  # --- Main UI Layout ---
10
  with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="orange"), title="地球物理學與AI應用") as demo:
 
 
 
11
  # --- Introduction Section ---
12
  gr.Markdown(content.course_introduction_md)
13
 
 
3
  from config import content, data, defaults
4
  from core import callbacks
5
 
6
+ def create_ui(visit_count_html: str):
7
+ """
8
+ Creates and returns the Gradio UI Blocks.
9
+
10
+ Args:
11
+ visit_count_html: The Markdown string to display the visit count.
12
+ """
13
 
14
  # --- Main UI Layout ---
15
  with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="orange"), title="地球物理學與AI應用") as demo:
16
+ # --- Display Visit Counter at the top ---
17
+ gr.Markdown(visit_count_html)
18
+
19
  # --- Introduction Section ---
20
  gr.Markdown(content.course_introduction_md)
21