E-slam commited on
Commit
19572cf
·
verified ·
1 Parent(s): 8f86080

Delete assets

Browse files
assets/AiSearch.py DELETED
@@ -1,492 +0,0 @@
1
-
2
- import flet as ft
3
- import json
4
- import pandas as pd
5
- import Bot_Page
6
- import Bot_Page_ٍSummary
7
- import time
8
- import utils
9
-
10
- df_laws = pd.read_excel("Data/UAE_Laws_LC_April_3.xlsx")
11
-
12
- def unique_ordered_list(law_ids):
13
- seen = set()
14
- unique_list = []
15
- for item in law_ids:
16
- if item not in seen:
17
- seen.add(item)
18
- unique_list.append(item)
19
- return unique_list
20
-
21
- def mawad_func(law_id):
22
- return [json.loads(item) for item in json_nodes if json.loads(item).get("File_ID") == str(law_id)]
23
-
24
- def main(page: ft.Page):
25
- page.theme = ft.Theme(
26
- color_scheme=ft.ColorScheme(
27
- primary=ft.colors.BLUE,
28
- secondary=ft.colors.CYAN,
29
- ),
30
- font_family="Arial"
31
- )
32
-
33
- page.bgcolor = ft.colors.WHITE
34
- page.window_maximized = True
35
- page.horizontal_alignment = ft.CrossAxisAlignment.STRETCH
36
- page.vertical_alignment = ft.MainAxisAlignment.START
37
-
38
- relevant_matches_active = False
39
- current_file_id = None
40
- current_hits = None
41
-
42
- def create_table(books, pages, hits):
43
- def create_cell(content, h, wid, is_header=False):
44
- return ft.Container(
45
- content=ft.Text(content, weight="bold" if is_header else None),
46
- border=ft.border.all(1, "cyan"),
47
- padding=ft.padding.all(8),
48
- border_radius=2,
49
- alignment=ft.alignment.center,
50
- width=wid,
51
- height=h
52
- )
53
-
54
- headers_height = 40
55
- headers_width = 250
56
-
57
- header = ft.Row(
58
- controls=[
59
- create_cell("الموضوع", headers_height, 500, is_header=True),
60
- create_cell("تاريخ الاصدار", headers_height, headers_width, is_header=True),
61
- create_cell("التشريع", headers_height, headers_width, is_header=True)
62
- ],
63
- alignment="center",
64
- spacing=0
65
- )
66
-
67
- values_height = 90
68
- values = ft.Row(
69
- controls=[
70
- create_cell(hits, values_height, 500),
71
- create_cell(pages, values_height, headers_width),
72
- create_cell(books, values_height, headers_width)
73
- ],
74
- alignment="center",
75
- spacing=0
76
- )
77
-
78
- table = ft.Column(
79
- controls=[
80
- header,
81
- values
82
- ],
83
- alignment="center",
84
- spacing=0
85
- )
86
-
87
- return table
88
-
89
- def on_search(e):
90
- loading_indicator.visible = True
91
- law_info_table.visible = False
92
-
93
- page.update()
94
-
95
- query = search_field.value
96
-
97
- if current_search_mode.value == "Mode 1 is selected":
98
-
99
- res = utils.Get_Azure_AI_RAG_Json(query,20)
100
-
101
- law_ids = [int(id.get("File_ID")) for id in res]
102
-
103
- unique_law_ids = unique_ordered_list(law_ids)
104
-
105
- results = df_laws[df_laws['Id'].isin(unique_law_ids)].reset_index()
106
-
107
- results['Id'] = pd.Categorical(results['Id'], categories=unique_law_ids, ordered=True)
108
-
109
- results = results.sort_values('Id').reset_index(drop=True)
110
-
111
- results = results.head(10)
112
-
113
- elif current_search_mode.value == "Mode 2 is selected":
114
-
115
- res = utils.by_law_title(query,20)
116
-
117
- law_ids = [int(id.get("File_ID")) for id in res]
118
-
119
- unique_law_ids = unique_ordered_list(law_ids)
120
-
121
- results = df_laws[df_laws['Id'].isin(unique_law_ids)].reset_index()
122
-
123
- results['Id'] = pd.Categorical(results['Id'], categories=unique_law_ids, ordered=True)
124
-
125
- results = results.sort_values('Id').reset_index(drop=True)
126
-
127
- results = results.head(10)
128
-
129
- table.rows.clear()
130
- for i in range(results.shape[0]):
131
-
132
- curr_id = int(results['Id'][i])
133
- count_df = (df_laws[df_laws['Id']== curr_id]).reset_index()['Subjects Count'][0]
134
-
135
- articles_count = int(count_df)
136
- table.rows.append(
137
- ft.DataRow(cells=[
138
- ft.DataCell(ft.IconButton(ft.icons.LINK, on_click=lambda e, link=results['short_url'][i]: page.launch_url(link))),
139
- ft.DataCell(ft.Text(articles_count, text_align=ft.TextAlign.RIGHT)),
140
- ft.DataCell(ft.Container(
141
- ft.Text(results['Description'][i], text_align=ft.TextAlign.RIGHT, rtl=True),
142
- alignment=ft.alignment.center_right
143
- )),
144
- ft.DataCell(ft.Container(
145
- ft.Text(results['Issue Date'][i], text_align=ft.TextAlign.RIGHT, rtl=True),
146
- alignment=ft.alignment.center_right
147
- )),
148
- ft.DataCell(ft.Container(
149
- ft.TextButton(results['Topic'][i], on_click=lambda e, file_id=results['Id'][i]: show_topic_details(file_id, res)),
150
- alignment=ft.alignment.center_right
151
- )),
152
- ])
153
- )
154
-
155
-
156
- loading_indicator.visible = False
157
- table.visible = True
158
- page.update()
159
-
160
- loading_indicator = ft.ProgressRing(visible=False)
161
-
162
- def show_topic_details(file_id, res):
163
- dialog_button.on_click = lambda e, fid=file_id :open_chat_dlg(e, fid)
164
- summary_button.on_click = lambda e, fid=file_id :open_summary_dlg(e, fid)
165
-
166
- nonlocal current_file_id, current_hits
167
- current_file_id = file_id
168
- current_hits = res
169
- table.visible = False
170
- law_info_table.visible = True
171
- info_df = df_laws[df_laws['Id'] == file_id].reset_index()
172
-
173
- description = info_df['Description'][0]
174
- issue_date = info_df['Issue Date'][0]
175
- link = info_df['short_url'][0]
176
- topic = info_df['Topic'][0]
177
-
178
- law_info_table.controls = [create_table(topic, issue_date, description)]
179
-
180
- mada_df = pd.read_csv(f"Data/Topics_CSV/{file_id}.csv")
181
- mada_df = mada_df[mada_df['Header'] != "Desc"]
182
-
183
- mawad_details = mada_df['Header'].to_list()
184
-
185
- if len(res) == 0:
186
- ordered_details = mawad_details
187
- hits = []
188
-
189
- else:
190
-
191
- hits = [item for item in res if item['File_ID'] == str(file_id)]
192
- hits = [item['Row_Header'] for item in hits]
193
-
194
- if relevant_matches_active:
195
-
196
- ordered_details = {header: index for index, header in enumerate(hits)}
197
-
198
- ordered_details = sorted(mawad_details, key=lambda x: ordered_details.get(x, float('inf')))
199
-
200
- else:
201
-
202
- ordered_details = mawad_details
203
-
204
- details_list.controls.clear()
205
- for item in ordered_details:
206
- if not relevant_matches_active or item in hits:
207
-
208
- bc = ft.colors.YELLOW if item in hits else ft.colors.WHITE
209
-
210
- curr_mada_text =(mada_df[mada_df['Header'] == item]).reset_index()['Header'][0] + " * " + (mada_df[mada_df['Header'] == item]).reset_index()['Text'][0]
211
-
212
- details_list.controls.append(
213
- ft.Container(
214
- content=ft.ElevatedButton(
215
- text=item,
216
- on_click=lambda e, text=curr_mada_text: show_mada_text(text),
217
- bgcolor=ft.colors.CYAN,
218
- color=bc
219
- ),
220
- alignment=ft.alignment.center_right,
221
- padding=ft.padding.all(10),
222
- border_radius=ft.border_radius.all(5),
223
- shadow=ft.BoxShadow(
224
- blur_radius=5,
225
- spread_radius=1,
226
- color=ft.colors.GREY_100,
227
- offset=ft.Offset(2, 2)
228
- )
229
- )
230
- )
231
- details_view.visible = True
232
- search_view.visible = False
233
- page.update()
234
-
235
- def show_mada_text(text):
236
-
237
- try:
238
- header, article = text.split('*', 1)
239
-
240
- header_text = ft.Text(header, weight=ft.FontWeight.BOLD, rtl=True, text_align=ft.TextAlign.CENTER)
241
-
242
- article_text = ft.Text(article.strip(), rtl=True, text_align=ft.TextAlign.RIGHT)
243
-
244
- column_controls = [header_text, article_text]
245
-
246
- except:
247
- column_controls = [ft.Text(text,rtl=True)]
248
-
249
- mada_column.content.controls = column_controls
250
-
251
- page.update()
252
-
253
- def go_back_to_search(e):
254
- details_view.visible = False
255
- search_view.visible = True
256
- table.visible = True
257
- page.update()
258
-
259
- def toggle_relevant_matches(e):
260
- nonlocal relevant_matches_active
261
- relevant_matches_active = not relevant_matches_active
262
- relevant_matches_button.bgcolor = ft.colors.YELLOW if relevant_matches_active else ft.colors.CYAN
263
- page.update()
264
- if current_file_id is not None:
265
- show_topic_details(current_file_id, current_hits)
266
-
267
- search_field = ft.TextField(label="أدخل أستفسارك", text_align=ft.TextAlign.RIGHT, expand=True)
268
- search_button = ft.ElevatedButton("بحث", icon=ft.icons.SEND, on_click=on_search, bgcolor=ft.colors.BLUE, color=ft.colors.WHITE)
269
-
270
- table = ft.DataTable(
271
- border=ft.border.all(2, "cyan"),
272
- border_radius=10,
273
- vertical_lines=ft.BorderSide(1, color="F6F5F5"),
274
- horizontal_lines=ft.BorderSide(1, "F6F5F5"),
275
- columns=[
276
- ft.DataColumn(label=ft.Text("رابط القانون", text_align=ft.TextAlign.RIGHT)),
277
- ft.DataColumn(label=ft.Text("المواد", text_align=ft.TextAlign.RIGHT)),
278
- ft.DataColumn(label=ft.Text("الموضوع", text_align=ft.TextAlign.RIGHT, rtl=True)),
279
- ft.DataColumn(label=ft.Text("تاريخ الإصدار", text_align=ft.TextAlign.RIGHT, rtl=True)),
280
- ft.DataColumn(label=ft.Text("التشريع", text_align=ft.TextAlign.RIGHT, rtl=True, width = 350)),
281
- ],
282
- rows=[]
283
- )
284
-
285
- details_list = ft.Column(scroll=ft.ScrollMode.AUTO)
286
- container_style = {
287
- "width": page.window_width / 2 - 20,
288
- "height": page.window_height - 250,
289
- "padding": 20,
290
- "bgcolor": ft.colors.WHITE,
291
- "border": ft.border.all(1, color=ft.colors.GREY_200),
292
- "border_radius": ft.border_radius.all(15),
293
- "shadow": ft.BoxShadow(
294
- blur_radius=20,
295
- spread_radius=2,
296
- color=ft.colors.BLACK12,
297
- offset=ft.Offset(4, 4)
298
- )
299
- }
300
-
301
- details_column = ft.Container(
302
- content=details_list,
303
- **container_style
304
- )
305
-
306
-
307
- mada_column = ft.Container(
308
- content=ft.Column(controls=[], scroll=ft.ScrollMode.AUTO, alignment=ft.MainAxisAlignment.CENTER,
309
- horizontal_alignment=ft.CrossAxisAlignment.CENTER),
310
- **container_style
311
- )
312
-
313
-
314
- def radio_mode(radio_group):
315
- if radio_group.value == "في محتوى التشريعات":
316
- current_search_mode.value = ("Mode 1 is selected")
317
- elif radio_group.value == "في عناوين التشريعات":
318
- current_search_mode.value = ("Mode 2 is selected")
319
-
320
- def on_radio_change(e):
321
- radio_mode(e.control)
322
-
323
- search_mode_radios = ft.RadioGroup(
324
- on_change=on_radio_change,
325
- value="في محتوى التشريعات",
326
- content=ft.Row(
327
- [
328
- ft.Row([ft.Text("في عناوين التشريعات", weight=ft.FontWeight.BOLD), ft.Radio(value="في عناوين التشريعات")]),
329
- ft.Row([ft.Text("في محتوى التشريعات", weight=ft.FontWeight.BOLD), ft.Radio(value="في محتوى التشريعات")]),
330
- ],
331
- alignment=ft.MainAxisAlignment.CENTER,
332
- spacing=80
333
- )
334
- )
335
-
336
- current_search_mode = ft.Text("", visible = False)
337
-
338
- back_button = ft.ElevatedButton(
339
- text="عودة",
340
- on_click=go_back_to_search,
341
- icon=ft.icons.ARROW_BACK_IOS_NEW_SHARP,
342
- bgcolor=ft.colors.CYAN,
343
- color=ft.colors.WHITE
344
- )
345
-
346
- relevant_matches_button = ft.ElevatedButton(
347
- text="نتائج البحث",
348
- on_click=toggle_relevant_matches,
349
- bgcolor=ft.colors.CYAN,
350
- color=ft.colors.WHITE,
351
- style=ft.ButtonStyle(
352
- shape=ft.RoundedRectangleBorder(radius=8),
353
- elevation=2,
354
- )
355
- )
356
-
357
- table_container = ft.Container(
358
- content=table,
359
- width=page.width,
360
- )
361
- search_view = ft.Column([
362
- ft.Row([search_field, search_button, loading_indicator], alignment=ft.MainAxisAlignment.END, spacing=10),
363
- search_mode_radios,
364
- current_search_mode,
365
- ], alignment=ft.MainAxisAlignment.START, spacing=20)
366
-
367
- dlg = ft.AlertDialog(
368
- modal=True,
369
- content = ft.Text(),
370
-
371
- )
372
-
373
- def open_summary_dlg(e, fid):
374
-
375
- bot_page = Bot_Page_ٍSummary.main(ft.Page, fid, df_laws)
376
- bot_page.controls[0].content.controls[0].content.controls[2].controls[0].on_click = lambda e: page.close(dlg)
377
-
378
- dlg.content = bot_page
379
- dlg.open = True
380
- dlg.update()
381
-
382
- time.sleep(1)
383
- bot_page.controls[1].on_click(None)
384
- time.sleep(1)
385
- bot_page.controls[2].on_click(None)
386
- page.update()
387
-
388
- def open_chat_dlg(e, fid):
389
-
390
- bot_page = Bot_Page.main(ft, ft.Page, utils.by_law_id, fid, df_laws)
391
- bot_page.controls[0].content.controls[0].content.controls[2].controls[0].on_click = lambda e: page.close(dlg)
392
-
393
- dlg.content = bot_page
394
- dlg.open = True
395
- dlg.update()
396
-
397
- dialog_button = ft.ElevatedButton(
398
- text="س , ج حول التشريع",
399
- icon=ft.icons.CHAT,
400
- tooltip="Required",
401
- on_click=open_chat_dlg,
402
- style=ft.ButtonStyle(
403
- bgcolor=ft.colors.WHITE,
404
- color=ft.colors.BLACK,
405
- shape=ft.RoundedRectangleBorder(radius=15),
406
- elevation=5,
407
- side=ft.BorderSide(
408
- color=ft.colors.GREY,
409
- width=1
410
- )
411
- )
412
- )
413
-
414
- summary_button = ft.ElevatedButton(
415
- text="ملخص التشريع",
416
- icon=ft.icons.MENU_BOOK,
417
- tooltip="ملخص",
418
- on_click=open_summary_dlg,
419
- style=ft.ButtonStyle(
420
- bgcolor=ft.colors.WHITE,
421
- color=ft.colors.BLACK,
422
- shape=ft.RoundedRectangleBorder(radius=15),
423
- elevation=5,
424
- side=ft.BorderSide(
425
- color=ft.colors.GREY,
426
- width=1
427
- )
428
- )
429
- )
430
-
431
-
432
- page.add(dlg)
433
-
434
-
435
- left_buttons_row = ft.Row(
436
- controls=[back_button, relevant_matches_button],
437
- alignment=ft.MainAxisAlignment.CENTER,
438
- spacing=20
439
- )
440
-
441
- right_buttons_row = ft.Row(
442
- controls=[dialog_button, summary_button],
443
- alignment=ft.MainAxisAlignment.CENTER,
444
- spacing=20
445
- )
446
-
447
- detailed_buttons_row = ft.Row(
448
- controls=[left_buttons_row, right_buttons_row],
449
- alignment=ft.MainAxisAlignment.SPACE_AROUND,
450
- spacing=20
451
- )
452
-
453
-
454
- law_info_table = ft.Row([ft.Text("")], alignment=ft.MainAxisAlignment.CENTER)
455
-
456
- details_view = ft.Column(
457
- [
458
- ft.Row(
459
- [
460
- law_info_table
461
- ],
462
- alignment=ft.MainAxisAlignment.CENTER
463
- ),
464
-
465
- detailed_buttons_row,
466
-
467
- ft.Row(
468
- [
469
- #ft.Text(" "),
470
- mada_column,
471
- details_column
472
- ],
473
- alignment=ft.MainAxisAlignment.CENTER,
474
- spacing=20
475
- )
476
- ],
477
- alignment=ft.MainAxisAlignment.CENTER,
478
- spacing=20,
479
- visible=False
480
- )
481
-
482
-
483
- law_info_table.visible = False
484
- page.add(ft.Column([search_view, table_container, details_view]))
485
- table.visible = False
486
-
487
- current_search_mode.value = "Mode 1 is selected"
488
-
489
-
490
- page.update()
491
-
492
- ft.app(target=main, assets_dir='assets')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/bot.png DELETED
Binary file (23 kB)
 
assets/header.png DELETED
Binary file (23 kB)
 
assets/user - Copy.png DELETED
Binary file (43.2 kB)
 
assets/user.png DELETED
Binary file (34.9 kB)