Spaces:
Paused
Paused
| import subprocess | |
| import sys | |
| def install(package): | |
| subprocess.check_call([sys.executable, "-m", "pip", "install", package]) | |
| install("transformers") | |
| install("torch") | |
| install("gradio") | |
| install("librosa") | |
| # Lanjut kode seperti biasa | |
| import gradio as gr | |
| from transformers import pipeline | |
| # ... dst | |
| import gradio as gr | |
| from transformers import pipeline | |
| # ID model dari tarteel-ai (model base Al-Quran) | |
| model_id = "tarteel-ai/whisper-base-ar-quran" | |
| # Pipeline otomatis tangani audio dan model | |
| pipe = pipeline( | |
| "automatic-speech-recognition", | |
| model=model_id, | |
| device="cpu", # Pakai CPU gratisan, cukup untuk base | |
| chunk_length_s=30, # Potong audio per 30 detik biar aman di RAM | |
| ) | |
| def transcribe(audio): | |
| if audio is None: | |
| return "" | |
| sr, y = audio # Gradio kasih tuple (sample_rate, numpy array) | |
| result = pipe({"sampling_rate": sr, "raw": y}) | |
| return result["text"] | |
| # Antarmuka | |
| demo = gr.Interface( | |
| fn=transcribe, | |
| inputs=gr.Audio(type="numpy", label="Unggah Audio Bacaan Al-Quran"), | |
| outputs=gr.Textbox(label="Hasil Transkripsi Arab", lines=3), | |
| title="🎙️ Whisper Base Al-Quran API", | |
| description="Model transkripsi bacaan Al-Quran akurat dari Tarteel AI.", | |
| ) | |
| demo.launch() |