Alide21 commited on
Commit
a858113
·
verified ·
1 Parent(s): 0a5f182

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -31
app.py CHANGED
@@ -14,7 +14,7 @@ api = HfApi()
14
 
15
  SURAH_NAMES = ["الفاتحة", "البقرة", "آل عمران", "النساء", "المائدة", "الأنعام", "الأعراف", "الأنفال", "التوبة", "يونس", "هود", "يوسف", "الرعد", "إبراهيم", "الحجر", "النحل", "الإسراء", "الكهف", "مريم", "طه", "الأنبياء", "الحج", "المؤمنون", "النور", "الفرقان", "الشعراء", "النمل", "القصص", "العنكبوت", "الروم", "لقمان", "السجدة", "الأحزاب", "سبأ", "فاطر", "يس", "الصافات", "ص", "الزمر", "غافر", "فصلت", "الشورى", "الزخرف", "الدخان", "الجاثية", "الأحقاف", "محمد", "الفتح", "الحجرات", "ق", "الذاريات", "الطور", "النجم", "القمر", "الرحمن", "الواقعة", "الحديد", "المجادلة", "الحشر", "الممتحنة", "الصف", "الجمعة", "المنافقون", "التغابن", "الطلاق", "التحريم", "الملك", "القلم", "الحاقة", "المعارج", "نوح", "الجن", "المزمل", "المدثر", "القيامة", "الإنسان", "المرسلات", "النبأ", "النازعات", "عبس", "التكوير", "الانفطار", "المطففين", "الانشقاق", "البروج", "الطارق", "الأعلى", "الغاشية", "الفجر", "البلد", "الشمس", "الليل", "الضحى", "الشرح", "التين", "العلق", "القدر", "البينة", "الزلزلة", "العاديات", "القارعة", "التكاثر", "العصر", "الهمزة", "الفيل", "قريش", "الماعون", "الكوثر", "الكافرون", "النصر", "المسد", "الإخلاص", "الفلق", "الناس"]
16
 
17
- # --- التنسيق البصري الفخم ---
18
  custom_css = """
19
  @import url('https://fonts.googleapis.com/css2?family=Amiri:wght@400;700&family=Reem+Kufi:wght@400;700&display=swap');
20
 
@@ -22,13 +22,12 @@ custom_css = """
22
 
23
  body { direction: rtl; background-color: #f0f2f5; }
24
 
25
- /* الهيدر مع خلفية الصورة المعتمة */
26
  .hero-header {
27
- background: linear-gradient(rgba(6, 70, 53, 0.85), rgba(6, 70, 53, 0.85)),
28
  url('https://images.unsplash.com/photo-1609599006353-e629aaabfeae?q=80&w=2070&auto=format&fit=crop');
29
  background-size: cover;
30
  background-position: center;
31
- padding: 40px 20px;
32
  border-radius: 0 0 50px 50px;
33
  text-align: center;
34
  color: white !important;
@@ -37,19 +36,30 @@ body { direction: rtl; background-color: #f0f2f5; }
37
 
38
  .hero-header h1, .hero-header p, .hero-header span { color: white !important; }
39
 
40
- .real-count { font-size: 4rem; color: var(--gold); font-weight: bold; line-height: 1; text-shadow: 2px 2px 10px rgba(0,0,0,0.5); }
 
 
 
 
 
 
 
 
41
 
 
42
  .instruction-box {
43
  background: #fff9e6;
44
- border-right: 5px solid var(--gold);
45
- padding: 15px;
46
  border-radius: 15px;
47
  margin: 20px 0;
48
- font-size: 1rem;
49
  box-shadow: 0 4px 6px rgba(0,0,0,0.05);
 
 
 
50
  }
51
 
52
- /* موحد لكل البطاقات */
53
  .custom-card {
54
  background: white !important;
55
  border-radius: 25px !important;
@@ -61,13 +71,11 @@ body { direction: rtl; background-color: #f0f2f5; }
61
 
62
  .ayah-text {
63
  font-family: 'Amiri', serif !important;
64
- font-size: 2.2rem !important;
65
  color: var(--dark-green);
66
  line-height: 1.8 !important;
67
  text-align: center;
68
  }
69
-
70
- .status-label { font-weight: bold; padding: 10px; border-radius: 10px; }
71
  """
72
 
73
  # --- المنطق الخلفي ---
@@ -91,11 +99,7 @@ with ThreadPoolExecutor(max_workers=10) as executor:
91
  ALL_AYAT = [item for sublist in results for item in sublist]
92
 
93
  def validate_ayah(v):
94
- """التحقق من طول الآية (أقل من 200 كلمة)"""
95
- word_count = len(v['text'].split())
96
- if word_count > 200:
97
- return False
98
- return True
99
 
100
  def jump_to_ayah(s_name, a_num):
101
  try:
@@ -105,7 +109,7 @@ def jump_to_ayah(s_name, a_num):
105
  if not validate_ayah(v):
106
  return "⚠️ عذراً، هذه الآية طويلة جداً (أكثر من 200 كلمة)", gr.update(), gr.update(), gr.update()
107
  return "✅ تم الانتقال للآية", f"<div class='ayah-text'>{v['text']}</div>", f"### {v['surah_name']} | آية {v['ayah']}", i
108
- return "⚠️ لم يتم العثور على الآية، تأكد من رقم الآية في السورة", gr.update(), gr.update(), gr.update()
109
  except:
110
  return "⚠️ يرجى إدخال رقم صحيح", gr.update(), gr.update(), gr.update()
111
 
@@ -114,25 +118,23 @@ def on_submit(audio, current_idx):
114
  v = ALL_AYAT[current_idx]
115
  try:
116
  api.upload_file(path_or_fileobj=audio, path_in_repo=f"data/s{v['surah']}_a{v['ayah']}_{uuid.uuid4().hex[:6]}.wav", repo_id=REPO_ID, repo_type="dataset", token=HF_TOKEN)
117
- # اختيار آية عشوائية تالية صالحة
118
  while True:
119
  next_idx = random.randint(0, len(ALL_AYAT)-1)
120
  if validate_ayah(ALL_AYAT[next_idx]): break
121
  nv = ALL_AYAT[next_idx]
122
- return "✅ تم الحفظ، جزاك الله خيراً", f"<div class='ayah-text'>{nv['text']}</div>", f"### {nv['surah_name']} | آية {nv['ayah']}", next_idx
123
  except Exception as e: return f"❌ فشل الرفع: {str(e)}", gr.update(), gr.update(), current_idx
124
 
125
  # --- واجهة المستخدم ---
126
- with gr.Blocks(title="مِنَصَّة تلاوة - ذكاء اصطناعي") as demo:
127
  idx_state = gr.State(random.randint(0, len(ALL_AYAT)-1))
128
 
129
- # 1. الهيدر الفخم
130
  gr.HTML(f"""
131
  <div class="hero-header">
132
  <h1>مِنَصَّة التِّلَاوَة</h1>
133
  <p>مشروع تقني لبناء نموذج ذكاء اصطناعي لتصحيح التجويد وتلاوة القرآن</p>
134
  <div style="margin-top:20px;">
135
- <span>إجمالي المساهمات الحقيقية</span>
136
  <div class="real-count">{get_real_total()}</div>
137
  </div>
138
  </div>
@@ -141,13 +143,12 @@ with gr.Blocks(title="مِنَصَّة تلاوة - ذكاء اصطناعي") as
141
  with gr.Column(elem_classes="gradio-container"):
142
  gr.HTML("""
143
  <div class="instruction-box">
144
- <b>💡 إرشادات:</b> يرجى قراءة الآية بوضوح وتجنب تكرار الكلمات عند الوقف الخاطئ.
145
- الهدف هو جمع تلاوات نقية لتدريب ذكاء اصطناعي يخدم كتاب الله.
146
  </div>
147
  """)
148
 
149
  with gr.Row():
150
- # اليمين: عرض الآية
151
  with gr.Column(scale=2):
152
  with gr.Column(elem_classes="custom-card"):
153
  v_init = ALL_AYAT[idx_state.value]
@@ -155,18 +156,17 @@ with gr.Blocks(title="مِنَصَّة تلاوة - ذكاء اصطناعي") as
155
  text_html = gr.HTML(f"<div class='ayah-text'>{v_init['text']}</div>")
156
  status_msg = gr.Markdown("")
157
  with gr.Row():
158
- send_btn = gr.Button("🎤 إرسال التلاوة", variant="primary")
159
  rnd_btn = gr.Button("🔄 آية عشوائية", variant="secondary")
160
 
161
- # اليسار: التحكم والتسجيل
162
  with gr.Column(scale=1):
163
  with gr.Column(elem_classes="custom-card"):
164
- gr.Markdown("### 🎙️ التسجيل الصوتي")
165
  audio_ui = gr.Audio(sources=["microphone"], type="filepath", label=None)
166
 
167
  with gr.Column(elem_classes="custom-card"):
168
- gr.Markdown("### 🔍 اختيار آية محددة")
169
- s_drop = gr.Dropdown(choices=SURAH_NAMES, label="السورة", value="الفاتحة")
170
  a_num = gr.Number(label="رقم الآية", value=1, precision=0)
171
  go_btn = gr.Button("انتقال سريع")
172
 
 
14
 
15
  SURAH_NAMES = ["الفاتحة", "البقرة", "آل عمران", "النساء", "المائدة", "الأنعام", "الأعراف", "الأنفال", "التوبة", "يونس", "هود", "يوسف", "الرعد", "إبراهيم", "الحجر", "النحل", "الإسراء", "الكهف", "مريم", "طه", "الأنبياء", "الحج", "المؤمنون", "النور", "الفرقان", "الشعراء", "النمل", "القصص", "العنكبوت", "الروم", "لقمان", "السجدة", "الأحزاب", "سبأ", "فاطر", "يس", "الصافات", "ص", "الزمر", "غافر", "فصلت", "الشورى", "الزخرف", "الدخان", "الجاثية", "الأحقاف", "محمد", "الفتح", "الحجرات", "ق", "الذاريات", "الطور", "النجم", "القمر", "الرحمن", "الواقعة", "الحديد", "المجادلة", "الحشر", "الممتحنة", "الصف", "الجمعة", "المنافقون", "التغابن", "الطلاق", "التحريم", "الملك", "القلم", "الحاقة", "المعارج", "نوح", "الجن", "المزمل", "المدثر", "القيامة", "الإنسان", "المرسلات", "النبأ", "النازعات", "عبس", "التكوير", "الانفطار", "المطففين", "الانشقاق", "البروج", "الطارق", "الأعلى", "الغاشية", "الفجر", "البلد", "الشمس", "الليل", "الضحى", "الشرح", "التين", "العلق", "القدر", "البينة", "الزلزلة", "العاديات", "القارعة", "التكاثر", "العصر", "الهمزة", "الفيل", "قريش", "الماعون", "الكوثر", "الكافرون", "النصر", "المسد", "الإخلاص", "الفلق", "الناس"]
16
 
17
+ # --- التنسيق البصري المحدث ---
18
  custom_css = """
19
  @import url('https://fonts.googleapis.com/css2?family=Amiri:wght@400;700&family=Reem+Kufi:wght@400;700&display=swap');
20
 
 
22
 
23
  body { direction: rtl; background-color: #f0f2f5; }
24
 
 
25
  .hero-header {
26
+ background: linear-gradient(rgba(6, 70, 53, 0.88), rgba(6, 70, 53, 0.88)),
27
  url('https://images.unsplash.com/photo-1609599006353-e629aaabfeae?q=80&w=2070&auto=format&fit=crop');
28
  background-size: cover;
29
  background-position: center;
30
+ padding: 45px 20px;
31
  border-radius: 0 0 50px 50px;
32
  text-align: center;
33
  color: white !important;
 
36
 
37
  .hero-header h1, .hero-header p, .hero-header span { color: white !important; }
38
 
39
+ /* الرقم أصبح أبيض الآن */
40
+ .real-count {
41
+ font-size: 4.5rem;
42
+ color: white;
43
+ font-weight: bold;
44
+ line-height: 1;
45
+ text-shadow: 0 0 15px rgba(255,255,255,0.3);
46
+ margin-top: 10px;
47
+ }
48
 
49
+ /* الإرشادات RTL */
50
  .instruction-box {
51
  background: #fff9e6;
52
+ border-right: 6px solid var(--gold);
53
+ padding: 18px;
54
  border-radius: 15px;
55
  margin: 20px 0;
56
+ font-size: 1.05rem;
57
  box-shadow: 0 4px 6px rgba(0,0,0,0.05);
58
+ direction: rtl;
59
+ text-align: right;
60
+ line-height: 1.6;
61
  }
62
 
 
63
  .custom-card {
64
  background: white !important;
65
  border-radius: 25px !important;
 
71
 
72
  .ayah-text {
73
  font-family: 'Amiri', serif !important;
74
+ font-size: 2.3rem !important;
75
  color: var(--dark-green);
76
  line-height: 1.8 !important;
77
  text-align: center;
78
  }
 
 
79
  """
80
 
81
  # --- المنطق الخلفي ---
 
99
  ALL_AYAT = [item for sublist in results for item in sublist]
100
 
101
  def validate_ayah(v):
102
+ return len(v['text'].split()) <= 200
 
 
 
 
103
 
104
  def jump_to_ayah(s_name, a_num):
105
  try:
 
109
  if not validate_ayah(v):
110
  return "⚠️ عذراً، هذه الآية طويلة جداً (أكثر من 200 كلمة)", gr.update(), gr.update(), gr.update()
111
  return "✅ تم الانتقال للآية", f"<div class='ayah-text'>{v['text']}</div>", f"### {v['surah_name']} | آية {v['ayah']}", i
112
+ return "⚠️ لم يتم العثور على الآية، تأكد من الرقم والاسم", gr.update(), gr.update(), gr.update()
113
  except:
114
  return "⚠️ يرجى إدخال رقم صحيح", gr.update(), gr.update(), gr.update()
115
 
 
118
  v = ALL_AYAT[current_idx]
119
  try:
120
  api.upload_file(path_or_fileobj=audio, path_in_repo=f"data/s{v['surah']}_a{v['ayah']}_{uuid.uuid4().hex[:6]}.wav", repo_id=REPO_ID, repo_type="dataset", token=HF_TOKEN)
 
121
  while True:
122
  next_idx = random.randint(0, len(ALL_AYAT)-1)
123
  if validate_ayah(ALL_AYAT[next_idx]): break
124
  nv = ALL_AYAT[next_idx]
125
+ return "✅ تم الحفظ بنجاح، بارك الله فيك", f"<div class='ayah-text'>{nv['text']}</div>", f"### {nv['surah_name']} | آية {nv['ayah']}", next_idx
126
  except Exception as e: return f"❌ فشل الرفع: {str(e)}", gr.update(), gr.update(), current_idx
127
 
128
  # --- واجهة المستخدم ---
129
+ with gr.Blocks(title="مِنَصَّة تلاوة") as demo:
130
  idx_state = gr.State(random.randint(0, len(ALL_AYAT)-1))
131
 
 
132
  gr.HTML(f"""
133
  <div class="hero-header">
134
  <h1>مِنَصَّة التِّلَاوَة</h1>
135
  <p>مشروع تقني لبناء نموذج ذكاء اصطناعي لتصحيح التجويد وتلاوة القرآن</p>
136
  <div style="margin-top:20px;">
137
+ <span style="font-size: 1.2rem; opacity: 0.9;">مساهمات الأمة</span>
138
  <div class="real-count">{get_real_total()}</div>
139
  </div>
140
  </div>
 
143
  with gr.Column(elem_classes="gradio-container"):
144
  gr.HTML("""
145
  <div class="instruction-box">
146
+ <b>💡 إرشادات المشاركة:</b> يرجى قراءة الآية الكريمة بوضوح وهدوء.
147
+ <br>تجنب تكرار الكلمات عند الوقف والابتداء لضمان دقة تدريب نموذج الذكاء الاصطناعي.
148
  </div>
149
  """)
150
 
151
  with gr.Row():
 
152
  with gr.Column(scale=2):
153
  with gr.Column(elem_classes="custom-card"):
154
  v_init = ALL_AYAT[idx_state.value]
 
156
  text_html = gr.HTML(f"<div class='ayah-text'>{v_init['text']}</div>")
157
  status_msg = gr.Markdown("")
158
  with gr.Row():
159
+ send_btn = gr.Button("🎤 إرسال المساهمة", variant="primary")
160
  rnd_btn = gr.Button("🔄 آية عشوائية", variant="secondary")
161
 
 
162
  with gr.Column(scale=1):
163
  with gr.Column(elem_classes="custom-card"):
164
+ gr.Markdown("### 🎙️ التسجيل")
165
  audio_ui = gr.Audio(sources=["microphone"], type="filepath", label=None)
166
 
167
  with gr.Column(elem_classes="custom-card"):
168
+ gr.Markdown("### 🔍 اختيار آية")
169
+ s_drop = gr.Dropdown(choices=SURAH_NAMES, label="اسم السورة", value="الفاتحة")
170
  a_num = gr.Number(label="رقم الآية", value=1, precision=0)
171
  go_btn = gr.Button("انتقال سريع")
172