Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -130,6 +130,20 @@ def save_to_parquet(records: List[dict], output_dir: str, max_size_mb: int = 500
|
|
| 130 |
|
| 131 |
return parquet_files
|
| 132 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
def process_audio(input_file):
|
| 134 |
if input_file is None:
|
| 135 |
return None, "Vui lòng upload file audio hoặc file zip!"
|
|
@@ -211,12 +225,33 @@ with gr.Blocks(title="Audio Transcription & Dataset Creator") as app:
|
|
| 211 |
label="Upload Audio File hoặc ZIP",
|
| 212 |
file_types=['.wav', '.mp3', '.flac', '.ogg', '.m4a', '.aac', '.zip']
|
| 213 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
process_btn = gr.Button("🚀 Bắt đầu xử lý", variant="primary")
|
| 215 |
|
| 216 |
with gr.Column():
|
| 217 |
output_file = gr.File(label="📦 Tải về Dataset ZIP")
|
| 218 |
status_text = gr.Textbox(label="📊 Trạng thái", lines=8)
|
| 219 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
process_btn.click(
|
| 221 |
fn=process_audio,
|
| 222 |
inputs=input_file,
|
|
@@ -230,7 +265,7 @@ with gr.Blocks(title="Audio Transcription & Dataset Creator") as app:
|
|
| 230 |
- Cột `transcription`: văn bản transcription
|
| 231 |
- Cột `file_name`: đường dẫn dạng `audio/filename_00001.wav`
|
| 232 |
- Các câu ngắn (< 2s) sẽ được gộp lại
|
| 233 |
-
- Format tên
|
| 234 |
""")
|
| 235 |
|
| 236 |
if __name__ == "__main__":
|
|
|
|
| 130 |
|
| 131 |
return parquet_files
|
| 132 |
|
| 133 |
+
def get_sample_files():
|
| 134 |
+
sample_dir = "Sample"
|
| 135 |
+
if not os.path.exists(sample_dir):
|
| 136 |
+
return []
|
| 137 |
+
|
| 138 |
+
audio_extensions = {'.wav', '.mp3', '.flac', '.ogg', '.m4a', '.aac', '.zip'}
|
| 139 |
+
sample_files = []
|
| 140 |
+
|
| 141 |
+
for file in os.listdir(sample_dir):
|
| 142 |
+
if Path(file).suffix.lower() in audio_extensions:
|
| 143 |
+
sample_files.append(os.path.join(sample_dir, file))
|
| 144 |
+
|
| 145 |
+
return sample_files
|
| 146 |
+
|
| 147 |
def process_audio(input_file):
|
| 148 |
if input_file is None:
|
| 149 |
return None, "Vui lòng upload file audio hoặc file zip!"
|
|
|
|
| 225 |
label="Upload Audio File hoặc ZIP",
|
| 226 |
file_types=['.wav', '.mp3', '.flac', '.ogg', '.m4a', '.aac', '.zip']
|
| 227 |
)
|
| 228 |
+
|
| 229 |
+
sample_files = get_sample_files()
|
| 230 |
+
if sample_files:
|
| 231 |
+
gr.Markdown("### 📂 Hoặc chọn file mẫu:")
|
| 232 |
+
sample_dropdown = gr.Dropdown(
|
| 233 |
+
choices=sample_files,
|
| 234 |
+
label="Chọn file mẫu",
|
| 235 |
+
interactive=True
|
| 236 |
+
)
|
| 237 |
+
load_sample_btn = gr.Button("📥 Load file mẫu", variant="secondary")
|
| 238 |
+
|
| 239 |
process_btn = gr.Button("🚀 Bắt đầu xử lý", variant="primary")
|
| 240 |
|
| 241 |
with gr.Column():
|
| 242 |
output_file = gr.File(label="📦 Tải về Dataset ZIP")
|
| 243 |
status_text = gr.Textbox(label="📊 Trạng thái", lines=8)
|
| 244 |
|
| 245 |
+
if sample_files:
|
| 246 |
+
def load_sample(sample_path):
|
| 247 |
+
return sample_path
|
| 248 |
+
|
| 249 |
+
load_sample_btn.click(
|
| 250 |
+
fn=load_sample,
|
| 251 |
+
inputs=sample_dropdown,
|
| 252 |
+
outputs=input_file
|
| 253 |
+
)
|
| 254 |
+
|
| 255 |
process_btn.click(
|
| 256 |
fn=process_audio,
|
| 257 |
inputs=input_file,
|
|
|
|
| 265 |
- Cột `transcription`: văn bản transcription
|
| 266 |
- Cột `file_name`: đường dẫn dạng `audio/filename_00001.wav`
|
| 267 |
- Các câu ngắn (< 2s) sẽ được gộp lại
|
| 268 |
+
- Format tên: train-00000-of-00007.parquet
|
| 269 |
""")
|
| 270 |
|
| 271 |
if __name__ == "__main__":
|