kdallash commited on
Commit
b057615
·
verified ·
1 Parent(s): 1c274fb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -103
app.py CHANGED
@@ -7,7 +7,7 @@ import html
7
  from sentence_transformers import SentenceTransformer
8
  import os
9
 
10
- os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "0"
11
 
12
  # ===============================
13
  # Load data & models (ONCE)
@@ -44,7 +44,7 @@ from retrieval import hybrid_search_fixed
44
  from utils import preprocess_query
45
 
46
  # ===============================
47
- # Helper functions (unchanged)
48
  # ===============================
49
  def safe_get(row, col):
50
  try:
@@ -69,7 +69,7 @@ def short_preview(text, length=300):
69
  return text[:length].rsplit(' ', 1)[0] + "..."
70
 
71
  # ===============================
72
- # Search Function (unchanged)
73
  # ===============================
74
  def search_hadith(query, top_k):
75
  if not query or not str(query).strip():
@@ -142,7 +142,7 @@ def search_hadith(query, top_k):
142
  return "\n".join(html_parts)
143
 
144
  # ===============================
145
- # PROFESSIONAL DARK MODE CSS + PERFECT ARABIC TYPOGRAPHY
146
  # ===============================
147
  custom_css = """
148
  @import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700&family=Noto+Sans+Arabic:wght@400;500;700&display=swap');
@@ -158,149 +158,78 @@ custom_css = """
158
  --button-primary-background-fill-hover: #2563eb !important;
159
  }
160
 
161
- /* Global dark + Arabic-first typography */
162
  body, .gradio-container, .gr-panel, .gr-box, .gr-form, .wrap, .panel, .block, footer {
163
  background-color: #020617 !important;
164
  color: #f1f5f9 !important;
165
- font-family: 'Cairo', 'Noto Sans Arabic', system-ui, -apple-system, sans-serif !important;
166
- }
167
- .gradio-container {
168
- max-width: 960px !important;
169
- margin: 0 auto !important;
170
  }
 
171
 
172
- /* Arabic text improvements */
173
  .text-rtl, .full-text, .summary, .title, .topic {
174
- font-family: 'Cairo', 'Noto Sans Arabic', system-ui, sans-serif !important;
175
  line-height: 2.05 !important;
176
- font-feature-settings: "kern" 1, "liga" 1;
177
  }
178
 
179
- /* Inputs & labels */
180
- label span, .label-wrap span, input, textarea, .gr-input, .gr-textarea {
181
  color: #f1f5f9 !important;
182
  background: #1e2937 !important;
183
  border-color: #475569 !important;
184
- font-family: 'Cairo', 'Noto Sans Arabic', system-ui, sans-serif !important;
185
  }
186
 
187
  /* Buttons */
188
- button {
189
- font-weight: 600 !important;
190
- border-radius: 10px !important;
191
- font-family: 'Cairo', system-ui, sans-serif !important;
192
- }
193
  button.primary {
194
  background: linear-gradient(90deg, #3b82f6, #60a5fa) !important;
 
195
  }
196
 
197
- /* Examples table (dark + clean) */
198
- .gr-examples, .gr-examples-wrapper, .gr-examples-table {
199
- background-color: #0f172a !important;
200
- border-radius: 14px !important;
201
- border: 1px solid #334155 !important;
202
- }
203
- .gr-examples th, .gr-examples td {
204
- background-color: #1e2937 !important;
205
- color: #e2e8f0 !important;
206
- border-color: #334155 !important;
207
- }
208
-
209
- /* Result Cards - Premium dark look */
210
- .results { margin-top: 24px; }
211
  .card {
212
  background: #1e2937 !important;
213
  border-radius: 18px !important;
214
  padding: 26px !important;
215
  margin-bottom: 24px !important;
216
- box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4) !important;
217
  border: 1px solid #334155 !important;
218
- transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1) !important;
219
  }
220
  .card:hover {
221
  transform: translateY(-8px);
222
- box-shadow: 0 25px 50px rgba(59, 130, 246, 0.15) !important;
223
- }
224
- .card-header {
225
- display: flex !important;
226
- justify-content: space-between !important;
227
- align-items: flex-start !important;
228
- gap: 20px !important;
229
- margin-bottom: 18px !important;
230
  }
231
  .index {
232
  background: linear-gradient(90deg, #3b82f6, #60a5fa) !important;
233
- color: #ffffff !important;
234
  padding: 7px 16px !important;
235
  border-radius: 9999px !important;
236
  font-weight: 700 !important;
237
- font-size: 13.5px !important;
238
- box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3) !important;
239
- }
240
- .title {
241
- font-size: 19px !important;
242
- font-weight: 700 !important;
243
- color: #f1f5f9 !important;
244
- }
245
- .topic {
246
- font-size: 14px !important;
247
- color: #94a3b8 !important;
248
  }
 
 
249
 
250
  .text-rtl {
251
- direction: rtl !important;
252
- text-align: right !important;
253
  background: #0f172a !important;
254
  border-radius: 12px !important;
255
  padding: 18px !important;
256
  border-right: 6px solid #3b82f6 !important;
257
- color: #e2e8f0 !important;
258
- font-size: 17px !important;
259
- }
260
- .text-rtl details > summary {
261
- cursor: pointer !important;
262
- font-weight: 600 !important;
263
- list-style: none !important;
264
  font-size: 17px !important;
265
- }
266
- .text-rtl details > summary::before {
267
- content: "▶ ";
268
- color: #60a5fa;
269
- font-size: 13px;
270
- }
271
- .text-rtl details[open] > summary::before {
272
- content: "▼ ";
273
- }
274
- .full-text {
275
- margin-top: 14px !important;
276
- padding-top: 14px !important;
277
- border-top: 1px solid #334155 !important;
278
  color: #e2e8f0 !important;
279
  }
280
 
281
- /* Footer link */
282
- .footer a {
283
- color: #60a5fa !important;
284
- font-weight: 600 !important;
285
- text-decoration: none !important;
286
- }
287
- .footer a:hover { text-decoration: underline !important; }
288
-
289
- .empty {
290
- font-size: 17px !important;
291
- color: #94a3b8 !important;
292
- text-align: center !important;
293
- padding: 50px 20px !important;
294
- }
295
 
296
  @media (max-width: 768px) {
297
  .card-header { flex-direction: column !important; }
298
- .text-rtl { font-size: 16.5px !important; }
299
  }
300
  """
301
 
302
  # ===============================
303
- # Gradio Interface - Dark + Arabic Optimized
304
  # ===============================
305
  interface = gr.Interface(
306
  fn=search_hadith,
@@ -331,14 +260,7 @@ interface = gr.Interface(
331
  ["فضل الصلاة على النبي ﷺ", 5]
332
  ],
333
  flagging_mode="never",
334
- theme=gr.themes.Dark(
335
- primary_hue="blue",
336
- secondary_hue="slate",
337
- neutral_hue="slate",
338
- spacing_size="md",
339
- radius_size="lg",
340
- text_size="md"
341
- ),
342
  css=custom_css
343
  )
344
 
 
7
  from sentence_transformers import SentenceTransformer
8
  import os
9
 
10
+ os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1" # ← Changed to 1 for faster model loading next time
11
 
12
  # ===============================
13
  # Load data & models (ONCE)
 
44
  from utils import preprocess_query
45
 
46
  # ===============================
47
+ # Helper functions
48
  # ===============================
49
  def safe_get(row, col):
50
  try:
 
69
  return text[:length].rsplit(' ', 1)[0] + "..."
70
 
71
  # ===============================
72
+ # Search Function (with Arabic messages)
73
  # ===============================
74
  def search_hadith(query, top_k):
75
  if not query or not str(query).strip():
 
142
  return "\n".join(html_parts)
143
 
144
  # ===============================
145
+ # PROFESSIONAL DARK MODE + PERFECT ARABIC TYPOGRAPHY CSS
146
  # ===============================
147
  custom_css = """
148
  @import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700&family=Noto+Sans+Arabic:wght@400;500;700&display=swap');
 
158
  --button-primary-background-fill-hover: #2563eb !important;
159
  }
160
 
161
+ /* Force dark + best Arabic font */
162
  body, .gradio-container, .gr-panel, .gr-box, .gr-form, .wrap, .panel, .block, footer {
163
  background-color: #020617 !important;
164
  color: #f1f5f9 !important;
165
+ font-family: 'Cairo', 'Noto Sans Arabic', system-ui, sans-serif !important;
 
 
 
 
166
  }
167
+ .gradio-container { max-width: 960px !important; margin: 0 auto !important; }
168
 
169
+ /* Arabic text optimization */
170
  .text-rtl, .full-text, .summary, .title, .topic {
171
+ font-family: 'Cairo', 'Noto Sans Arabic', sans-serif !important;
172
  line-height: 2.05 !important;
 
173
  }
174
 
175
+ /* Inputs */
176
+ label span, input, textarea, .gr-input, .gr-textarea {
177
  color: #f1f5f9 !important;
178
  background: #1e2937 !important;
179
  border-color: #475569 !important;
 
180
  }
181
 
182
  /* Buttons */
 
 
 
 
 
183
  button.primary {
184
  background: linear-gradient(90deg, #3b82f6, #60a5fa) !important;
185
+ font-weight: 600 !important;
186
  }
187
 
188
+ /* Cards - Premium dark look */
 
 
 
 
 
 
 
 
 
 
 
 
 
189
  .card {
190
  background: #1e2937 !important;
191
  border-radius: 18px !important;
192
  padding: 26px !important;
193
  margin-bottom: 24px !important;
194
+ box-shadow: 0 10px 30px rgba(0,0,0,0.4) !important;
195
  border: 1px solid #334155 !important;
196
+ transition: all 0.35s ease !important;
197
  }
198
  .card:hover {
199
  transform: translateY(-8px);
200
+ box-shadow: 0 25px 50px rgba(59, 130, 246, 0.2) !important;
 
 
 
 
 
 
 
201
  }
202
  .index {
203
  background: linear-gradient(90deg, #3b82f6, #60a5fa) !important;
204
+ color: #fff !important;
205
  padding: 7px 16px !important;
206
  border-radius: 9999px !important;
207
  font-weight: 700 !important;
 
 
 
 
 
 
 
 
 
 
 
208
  }
209
+ .title { font-size: 19px !important; font-weight: 700 !important; }
210
+ .topic { font-size: 14px !important; color: #94a3b8 !important; }
211
 
212
  .text-rtl {
 
 
213
  background: #0f172a !important;
214
  border-radius: 12px !important;
215
  padding: 18px !important;
216
  border-right: 6px solid #3b82f6 !important;
 
 
 
 
 
 
 
217
  font-size: 17px !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
218
  color: #e2e8f0 !important;
219
  }
220
 
221
+ /* Rest of the styles (same as before - clean & professional) */
222
+ .results { margin-top: 24px; }
223
+ .footer a { color: #60a5fa !important; font-weight: 600 !important; }
224
+ .empty { color: #94a3b8 !important; text-align: center; padding: 50px 20px; font-size: 17px; }
 
 
 
 
 
 
 
 
 
 
225
 
226
  @media (max-width: 768px) {
227
  .card-header { flex-direction: column !important; }
 
228
  }
229
  """
230
 
231
  # ===============================
232
+ # Gradio Interface (Fixed for 6.9.0)
233
  # ===============================
234
  interface = gr.Interface(
235
  fn=search_hadith,
 
260
  ["فضل الصلاة على النبي ﷺ", 5]
261
  ],
262
  flagging_mode="never",
263
+ theme=gr.themes.Soft(), # ← FIXED: Compatible with Gradio 6.9.0
 
 
 
 
 
 
 
264
  css=custom_css
265
  )
266