shiue2000 commited on
Commit
3e937c7
Β·
verified Β·
1 Parent(s): 4eee741

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -2
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import matplotlib.pyplot as plt
2
  import io
3
  import base64
@@ -8,6 +9,7 @@ import networkx as nx
8
  from datetime import datetime, timedelta
9
  import gradio as gr
10
  import logging
 
11
 
12
  # ===== ε­—εž‹θˆ‡ζ¨£εΌ =====
13
  plt.rcParams['font.sans-serif'] = ['Microsoft JhengHei', 'Noto Sans TC', 'SimHei', 'Arial Unicode MS']
@@ -200,6 +202,9 @@ def run_analysis():
200
  }
201
  news_table = "<p>η„‘ζ–°θžθ³‡ζ–™</p>"
202
 
 
 
 
203
  # --- εƒθˆ‡θ‘¨ ---
204
  engagement_table = f"""
205
  <table class="min-w-full bg-white border border-gray-200">
@@ -219,7 +224,8 @@ def run_analysis():
219
  with open(template_path, encoding='utf-8') as f:
220
  html_template = f.read()
221
 
222
- html_content = html_template.format(
 
223
  report_date=datetime.now().strftime('%Y-%m-%d %H:%M'),
224
  engagement_table=engagement_table if engagement_table else "<p>ζœͺζδΎ›δΊ’ε‹•ζ•Έζ“š</p>",
225
  news_summary=news_summary if news_summary else "<p>ζœͺζδΎ›ζ–°θžζ‘˜θ¦</p>",
@@ -240,4 +246,4 @@ if __name__ == "__main__":
240
  outputs=gr.HTML(),
241
  title="2026 ι«˜ι›„εΈ‚ι•·ιΈθˆ‰θΌΏζƒ…εˆ†ζž"
242
  )
243
- iface.launch(server_name="0.0.0.0", server_port=7860)
 
1
+ import pandas as pd
2
  import matplotlib.pyplot as plt
3
  import io
4
  import base64
 
9
  from datetime import datetime, timedelta
10
  import gradio as gr
11
  import logging
12
+ from jinja2 import Template
13
 
14
  # ===== ε­—εž‹θˆ‡ζ¨£εΌ =====
15
  plt.rcParams['font.sans-serif'] = ['Microsoft JhengHei', 'Noto Sans TC', 'SimHei', 'Arial Unicode MS']
 
202
  }
203
  news_table = "<p>η„‘ζ–°θžθ³‡ζ–™</p>"
204
 
205
+ # Convert news_summary to list of tuples to support iteration in template
206
+ news_summary = list(news_summary.items())
207
+
208
  # --- εƒθˆ‡θ‘¨ ---
209
  engagement_table = f"""
210
  <table class="min-w-full bg-white border border-gray-200">
 
224
  with open(template_path, encoding='utf-8') as f:
225
  html_template = f.read()
226
 
227
+ template = Template(html_template)
228
+ html_content = template.render(
229
  report_date=datetime.now().strftime('%Y-%m-%d %H:%M'),
230
  engagement_table=engagement_table if engagement_table else "<p>ζœͺζδΎ›δΊ’ε‹•ζ•Έζ“š</p>",
231
  news_summary=news_summary if news_summary else "<p>ζœͺζδΎ›ζ–°θžζ‘˜θ¦</p>",
 
246
  outputs=gr.HTML(),
247
  title="2026 ι«˜ι›„εΈ‚ι•·ιΈθˆ‰θΌΏζƒ…εˆ†ζž"
248
  )
249
+ iface.launch(server_name="0.0.0.0", server_port=7860)