Spaces:
Sleeping
Sleeping
File size: 1,805 Bytes
bf61cc2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
import pandas as pd
import gradio as gr
# Load Parquet data
df = pd.read_parquet('audio_and_text.parquet')
# Define function to fetch audio and text by number or index
def fetch_record(index):
index = int(index)
if 0 <= index < len(df):
record = df.iloc[index]
number = record['number']
diacritics_audio = (record['with_diacritics_audio'], "audio.wav")
no_diacritics_audio = (record['no_diacritics_audio'], "audio.wav")
diacritics_text = record['diacritics_text']
no_diacritics_text = record['no_diacritics_text']
return (f"Record Number: {number}",
diacritics_audio, diacritics_text,
no_diacritics_audio, no_diacritics_text)
else:
return ("Index out of range.", None, "", None, "")
# Gradio UI setup
with gr.Blocks() as demo:
gr.Markdown("## π Arabic Audio & Text Browser")
index_input = gr.Number(label="Enter Record Index", value=0, precision=0)
btn_fetch = gr.Button("Fetch Record")
record_label = gr.Label(label="Record Info")
with gr.Row():
with gr.Column():
diacritics_audio_player = gr.Audio(label="Audio (With Diacritics)")
diacritics_text_output = gr.Textbox(label="Text (With Diacritics)", lines=5)
with gr.Column():
no_diacritics_audio_player = gr.Audio(label="Audio (No Diacritics)")
no_diacritics_text_output = gr.Textbox(label="Text (No Diacritics)", lines=5)
btn_fetch.click(fn=fetch_record,
inputs=index_input,
outputs=[record_label,
diacritics_audio_player, diacritics_text_output,
no_diacritics_audio_player, no_diacritics_text_output])
# Launch the app
demo.launch()
|