MK-316 commited on
Commit
ffb422b
1 Parent(s): 1d6d47b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -8
app.py CHANGED
@@ -11,17 +11,21 @@ def load_data(level):
11
  data = pd.read_csv(csv_file_path)
12
  return data
13
 
14
- def generate_speech(level, x, y, audio_option):
15
  data = load_data(level)
16
 
17
  x, y = int(x), int(y)
18
- filtered_df = data[(data['SID'] >= x) & (data['SID'] <= y)]
 
 
 
19
 
20
  combined_audio = AudioSegment.silent(duration=1000)
21
 
22
  for _, row in filtered_df.iterrows():
23
  if audio_option == "Audio with number":
24
- sentence = f"Number {row['SID']}. {row['SID']} is {row['POS']}."
 
25
  else: # "Audio without number"
26
  sentence = f"{row['WORD']}!"
27
 
@@ -37,17 +41,19 @@ def generate_speech(level, x, y, audio_option):
37
  mp3_io.seek(0)
38
  return mp3_io.getvalue()
39
 
 
40
  iface = gr.Interface(
41
  fn=generate_speech,
42
  inputs=[
43
- gr.Dropdown(label="Select Level (3K: A1, A2, B1, B2, C1; 5K: additional B2 and C1)", choices=['A1', 'A2', 'B1', 'B2', 'C1', '5K']),
44
- gr.Number(label="Start Number (x)"),
45
- gr.Number(label="End Number (y)"),
46
- gr.Radio(label="Audio Option", choices=["Audio with number", "Audio without number"])
 
47
  ],
48
  outputs=gr.Audio(label="Generated Speech"),
49
  title="Oxford Learner Vocabulary by CEFR levels: Learn with Sound",
50
- description="Choose a level, define the starting and ending numbers, and select the audio option. The system will create a single audio file. After submission, you have the option to download the audio file."
51
  )
52
 
53
  iface.launch(share=True, debug=True)
 
11
  data = pd.read_csv(csv_file_path)
12
  return data
13
 
14
+ def generate_speech(level, x, y, audio_option, pos_filter):
15
  data = load_data(level)
16
 
17
  x, y = int(x), int(y)
18
+ if pos_filter != "Any":
19
+ filtered_df = data[(data['SID'] >= x) & (data['SID'] <= y) & (data['POS'].str.lower() == pos_filter.lower())]
20
+ else:
21
+ filtered_df = data[(data['SID'] >= x) & (data['SID'] <= y)]
22
 
23
  combined_audio = AudioSegment.silent(duration=1000)
24
 
25
  for _, row in filtered_df.iterrows():
26
  if audio_option == "Audio with number":
27
+ # Correcting the sentence structure to include both SID and the word's details properly
28
+ sentence = f"Number {row['SID']}. {row['WORD']}! {row['WORD']} is a {row['POS']}."
29
  else: # "Audio without number"
30
  sentence = f"{row['WORD']}!"
31
 
 
41
  mp3_io.seek(0)
42
  return mp3_io.getvalue()
43
 
44
+
45
  iface = gr.Interface(
46
  fn=generate_speech,
47
  inputs=[
48
+ gr.Dropdown(label="Select Level", choices=['A1', 'A2', 'B1', 'B2', 'C1', '5K']),
49
+ gr.Number(label="Range: Start Number (x)"),
50
+ gr.Number(label="Range: End Number (y)"),
51
+ gr.Radio(label="Audio Option", choices=["Audio with number", "Audio without number"]),
52
+ gr.Dropdown(label="Select Part of Speech", choices=["Any", "Noun", "Verb", "Adjective", "Adverb"]) # Corrected line
53
  ],
54
  outputs=gr.Audio(label="Generated Speech"),
55
  title="Oxford Learner Vocabulary by CEFR levels: Learn with Sound",
56
+ description="Choose a level, define the starting and ending numbers, select the audio option, and filter by Part of Speech if desired. The system will create a single audio file. After submission, you have the option to download the audio file."
57
  )
58
 
59
  iface.launch(share=True, debug=True)