OzoneAsai commited on
Commit
6bba304
·
verified ·
1 Parent(s): 7365b85

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -15
app.py CHANGED
@@ -26,27 +26,27 @@ os.makedirs(AUDIO_DIR, exist_ok=True)
26
  # Flashcards data
27
  flashcards = {
28
  'A': {
29
- 'english_sentences': list(translation_dict_A.keys()),
30
  'japanese_translations': list(translation_dict_A.values())
31
  },
32
  'B': {
33
- 'english_sentences': list(translation_dict_B.keys()),
34
  'japanese_translations': list(translation_dict_B.values())
35
  },
36
  'C': {
37
- 'english_sentences': list(translation_dict_C.keys()),
38
  'japanese_translations': list(translation_dict_C.values())
39
  },
40
  'D': {
41
- 'english_sentences': list(translation_dict_D.keys()),
42
  'japanese_translations': list(translation_dict_D.values())
43
  },
44
  'F': {
45
- 'english_sentences': list(translation_dict_F.keys()),
46
  'japanese_translations': list(translation_dict_F.values())
47
  },
48
  'G': {
49
- 'english_sentences': list(translation_dict_G.keys()),
50
  'japanese_translations': list(translation_dict_G.values())
51
  }
52
  }
@@ -59,7 +59,7 @@ def generate_audio(text, set_name, index):
59
 
60
  if not os.path.exists(filepath):
61
  logging.info(f"Generating audio file: {filepath}")
62
- tts = gTTS(text=text, lang='en')
63
  tts.save(filepath)
64
  else:
65
  logging.info(f"Using existing audio file: {filepath}")
@@ -80,7 +80,7 @@ def flashcards_page():
80
  if set_name not in flashcards:
81
  return "Set not found", 404
82
 
83
- total = len(flashcards[set_name]['english_sentences'])
84
  if not (0 <= index < total):
85
  return "Index out of range", 404
86
 
@@ -89,7 +89,7 @@ def flashcards_page():
89
  set_name=set_name,
90
  index=index,
91
  total=total,
92
- english=flashcards[set_name]['english_sentences'][index],
93
  japanese=flashcards[set_name]['japanese_translations'][index],
94
  audio_url=url_for('static', filename=f"audio/{set_name}_{index}.mp3")
95
  )
@@ -101,23 +101,23 @@ def api_flashcards():
101
  index = int(request.args.get('index', 0))
102
 
103
  if set_name in flashcards:
104
- english_sentences = flashcards[set_name]['english_sentences']
105
  japanese_translations = flashcards[set_name]['japanese_translations']
106
- total = len(english_sentences)
107
 
108
  if 0 <= index < total:
109
- english = english_sentences[index]
110
  japanese = japanese_translations[index]
111
 
112
  # Generate audio and get the URL
113
- audio_path = generate_audio(english, set_name, index)
114
  audio_url = url_for('static', filename=f"audio/{set_name}_{index}.mp3")
115
 
116
  return jsonify({
117
  'set_name': set_name,
118
  'index': index,
119
  'total': total,
120
- 'english': english,
121
  'japanese': japanese,
122
  'audio_url': audio_url
123
  })
@@ -127,4 +127,4 @@ def api_flashcards():
127
  return jsonify({'error': 'Set not found'}), 404
128
 
129
  if __name__ == '__main__':
130
- app.run(debug=True, host="0.0.0.0", port=7860)
 
26
  # Flashcards data
27
  flashcards = {
28
  'A': {
29
+ 'chinese_sentences': list(translation_dict_A.keys()),
30
  'japanese_translations': list(translation_dict_A.values())
31
  },
32
  'B': {
33
+ 'chinese_sentences': list(translation_dict_B.keys()),
34
  'japanese_translations': list(translation_dict_B.values())
35
  },
36
  'C': {
37
+ 'chinese_sentences': list(translation_dict_C.keys()),
38
  'japanese_translations': list(translation_dict_C.values())
39
  },
40
  'D': {
41
+ 'chinese_sentences': list(translation_dict_D.keys()),
42
  'japanese_translations': list(translation_dict_D.values())
43
  },
44
  'F': {
45
+ 'chinese_sentences': list(translation_dict_F.keys()),
46
  'japanese_translations': list(translation_dict_F.values())
47
  },
48
  'G': {
49
+ 'chinese_sentences': list(translation_dict_G.keys()),
50
  'japanese_translations': list(translation_dict_G.values())
51
  }
52
  }
 
59
 
60
  if not os.path.exists(filepath):
61
  logging.info(f"Generating audio file: {filepath}")
62
+ tts = gTTS(text=text, lang='zh-cn') # Set language to Chinese
63
  tts.save(filepath)
64
  else:
65
  logging.info(f"Using existing audio file: {filepath}")
 
80
  if set_name not in flashcards:
81
  return "Set not found", 404
82
 
83
+ total = len(flashcards[set_name]['chinese_sentences'])
84
  if not (0 <= index < total):
85
  return "Index out of range", 404
86
 
 
89
  set_name=set_name,
90
  index=index,
91
  total=total,
92
+ chinese=flashcards[set_name]['chinese_sentences'][index],
93
  japanese=flashcards[set_name]['japanese_translations'][index],
94
  audio_url=url_for('static', filename=f"audio/{set_name}_{index}.mp3")
95
  )
 
101
  index = int(request.args.get('index', 0))
102
 
103
  if set_name in flashcards:
104
+ chinese_sentences = flashcards[set_name]['chinese_sentences']
105
  japanese_translations = flashcards[set_name]['japanese_translations']
106
+ total = len(chinese_sentences)
107
 
108
  if 0 <= index < total:
109
+ chinese = chinese_sentences[index]
110
  japanese = japanese_translations[index]
111
 
112
  # Generate audio and get the URL
113
+ audio_path = generate_audio(chinese, set_name, index)
114
  audio_url = url_for('static', filename=f"audio/{set_name}_{index}.mp3")
115
 
116
  return jsonify({
117
  'set_name': set_name,
118
  'index': index,
119
  'total': total,
120
+ 'chinese': chinese,
121
  'japanese': japanese,
122
  'audio_url': audio_url
123
  })
 
127
  return jsonify({'error': 'Set not found'}), 404
128
 
129
  if __name__ == '__main__':
130
+ app.run(debug=True, host="0.0.0.0", port=7860)