File size: 2,380 Bytes
0f793cd
 
 
5264ee5
0f793cd
 
2ea79b7
0f793cd
1885335
 
 
0f793cd
1885335
0f793cd
1885335
 
 
 
 
 
 
 
 
 
0f793cd
1885335
 
 
 
0f793cd
 
 
1885335
 
5264ee5
1885335
 
 
0f793cd
1885335
0f793cd
1885335
0f793cd
 
 
1885335
 
 
 
 
 
0f793cd
 
 
1885335
0f793cd
 
 
 
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
52
53
54
55
56
57
58
59
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()