Update app.py
Browse files
app.py
CHANGED
@@ -4,26 +4,27 @@ from pydub import AudioSegment
|
|
4 |
import pandas as pd
|
5 |
import io
|
6 |
|
7 |
-
csv_files = {"A1":"OF3KA1.csv","A2":"OF3KA2.csv","B1":"OF3KB1.csv","B2":"OF3KB2.csv","C1":"OF3KC1.csv","5K":"OF5K.csv"}
|
8 |
|
9 |
-
# Function to load the DataFrame based on level selection
|
10 |
def load_data(level):
|
11 |
-
|
12 |
-
csv_file_path = f"./{csv_files[level]}" # This correctly uses the dictionary
|
13 |
data = pd.read_csv(csv_file_path)
|
14 |
return data
|
15 |
|
16 |
-
def generate_speech(level, x, y):
|
17 |
-
data = load_data(level)
|
18 |
|
19 |
-
# Ensure x and y are integers and within range
|
20 |
x, y = int(x), int(y)
|
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 |
-
|
|
|
|
|
|
|
|
|
27 |
tts = gTTS(text=sentence, lang='en')
|
28 |
mp3_fp = io.BytesIO()
|
29 |
tts.write_to_fp(mp3_fp)
|
@@ -36,17 +37,17 @@ def generate_speech(level, x, y):
|
|
36 |
mp3_io.seek(0)
|
37 |
return mp3_io.getvalue()
|
38 |
|
39 |
-
# Interface with updated level selection including all specified options
|
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 |
],
|
47 |
outputs=gr.Audio(label="Generated Speech"),
|
48 |
title="Oxford Learner Vocabulary by CEFR levels: Learn with Sound",
|
49 |
-
description="Choose a level
|
50 |
)
|
51 |
|
52 |
iface.launch(share=True, debug=True)
|
|
|
4 |
import pandas as pd
|
5 |
import io
|
6 |
|
7 |
+
csv_files = {"A1": "OF3KA1.csv", "A2": "OF3KA2.csv", "B1": "OF3KB1.csv", "B2": "OF3KB2.csv", "C1": "OF3KC1.csv", "5K": "OF5K.csv"}
|
8 |
|
|
|
9 |
def load_data(level):
|
10 |
+
csv_file_path = f"/content/{csv_files[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 |
+
|
28 |
tts = gTTS(text=sentence, lang='en')
|
29 |
mp3_fp = io.BytesIO()
|
30 |
tts.write_to_fp(mp3_fp)
|
|
|
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)
|