dayuian commited on
Commit
9a2c62d
·
verified ·
1 Parent(s): 275d15c

Update sentences.py

Browse files
Files changed (1) hide show
  1. sentences.py +8 -9
sentences.py CHANGED
@@ -49,19 +49,19 @@ def save_sentence(word, phonetic, sentence, source, model):
49
 
50
  def generate_sentences(words, source, use_ai, model_name):
51
  result_display = ""
52
- status_log = []
 
 
 
53
 
54
- for word in tqdm(words, desc="處理單字"):
55
- # 1. 查單字音標
56
  word_info = get_word_info(source, word)
57
  phonetic = word_info['phonetic'] if word_info else "無"
58
 
59
- # 2. 查句庫
60
  sentence_records = get_sentences_by_word(word)
61
 
62
- # 3. 判斷是否用AI
63
  if use_ai or not sentence_records:
64
  try:
 
65
  sentence = generate_sentence(word, model_name)
66
  save_sentence(word, phonetic, sentence, 'ai', model_name)
67
  source_used = 'ai'
@@ -71,12 +71,10 @@ def generate_sentences(words, source, use_ai, model_name):
71
  source_used = "error"
72
  model_used = None
73
  else:
74
- # 取第一筆句庫資料
75
  sentence = sentence_records[0][2]
76
  source_used = sentence_records[0][3]
77
  model_used = sentence_records[0][4]
78
 
79
- # 4. 組裝顯示內容
80
  result_display += f"""
81
  <div style="margin-bottom: 10px; padding: 8px; border-left: 4px solid #4CAF50; background-color: #f9f9f9;">
82
  <strong>單字:</strong> {word} <br>
@@ -86,6 +84,7 @@ def generate_sentences(words, source, use_ai, model_name):
86
  </div>
87
  """
88
 
89
- status_log.append(f"✅ {word}:{source_used}")
 
 
90
 
91
- return result_display, "\n".join(status_log)
 
49
 
50
  def generate_sentences(words, source, use_ai, model_name):
51
  result_display = ""
52
+ current_status = ""
53
+
54
+ for i, word in enumerate(words):
55
+ current_status = f"⏳ 處理中:{i + 1}/{len(words)} - [{word}] 正在查詢句子..."
56
 
 
 
57
  word_info = get_word_info(source, word)
58
  phonetic = word_info['phonetic'] if word_info else "無"
59
 
 
60
  sentence_records = get_sentences_by_word(word)
61
 
 
62
  if use_ai or not sentence_records:
63
  try:
64
+ current_status = f"🤖 使用 AI 生成 [{word}] 的句子中... (模型:{model_name})"
65
  sentence = generate_sentence(word, model_name)
66
  save_sentence(word, phonetic, sentence, 'ai', model_name)
67
  source_used = 'ai'
 
71
  source_used = "error"
72
  model_used = None
73
  else:
 
74
  sentence = sentence_records[0][2]
75
  source_used = sentence_records[0][3]
76
  model_used = sentence_records[0][4]
77
 
 
78
  result_display += f"""
79
  <div style="margin-bottom: 10px; padding: 8px; border-left: 4px solid #4CAF50; background-color: #f9f9f9;">
80
  <strong>單字:</strong> {word} <br>
 
84
  </div>
85
  """
86
 
87
+ current_status = "✅ 所有單字處理完成!"
88
+
89
+ return result_display, current_status
90