aboalaa1472's picture
Update app.py
2ea79b7 verified
import os
import gradio as gr
from gradio_client import Client, handle_file
from surahs_list import QURAN_SURAHS
HF_TOKEN = os.getenv("HF_TOKEN")
client = Client("aboalaa1472/Quran_ASR", token=HF_TOKEN)
SURAH_CHOICES = [f"{num} - {name}" for num, name in QURAN_SURAHS.items()]
def process_quran_asr(audio_input, surah_choice):
if audio_input is None:
return "برجاء رفع ملف صوتي أو التسجيل", None, None, None, None
try:
result = client.predict(
uploaded_audio=handle_file(audio_input),
mic_audio=handle_file(audio_input),
surah_choice=surah_choice,
api_name="/run_full_system"
)
return result
except Exception as e:
return f"حدث خطأ أثناء الاتصال بالخادم: {str(e)}", None, None, None, None
# 2. بناء الواجهة العامة
with gr.Blocks(title="نظام تصحيح التلاوة") as demo:
gr.Markdown("# 📖 نظام التعرف على القراءة وتصحيح التلاوة")
gr.Markdown("هذه واجهة مستخدم عامة، الكود الأساسي محفوظ في مساحة خاصة.")
with gr.Row():
with gr.Column():
audio_in = gr.Audio(
label="🎙️ سجل صوتك أو ارفع ملف",
type="filepath"
)
surah_dropdown = gr.Dropdown(
choices=SURAH_CHOICES,
label="🕌 اختر السورة",
value=SURAH_CHOICES[0]
)
btn = gr.Button("إرسال للتحليل", variant="primary")
with gr.Column():
out_text = gr.Textbox(label="📝 النص المستخرج من صوتك")
with gr.Row():
out_word_report = gr.File(label="📄 تقرير أخطاء الكلمات")
out_tajweed_report = gr.File(label="✍️ تقرير أخطاء التشكيل")
with gr.Row():
out_verses = gr.File(label="📖 نص الآيات المكتشفة")
out_original = gr.File(label="💾 ملف النص الأصلي")
btn.click(
fn=process_quran_asr,
inputs=[audio_in, surah_dropdown],
outputs=[out_text, out_word_report, out_tajweed_report, out_verses, out_original]
)
demo.launch()