FDSRashid commited on
Commit
1d34284
·
verified ·
1 Parent(s): 2a8501c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ import pyarabic.araby as araby
4
+ import pandas as pd
5
+ import re
6
+ from datasets import load_dataset
7
+ from datasets import Features
8
+ from datasets import Value
9
+ from datasets import Dataset
10
+
11
+
12
+ Secret_token = os.getenv('HF_token')
13
+
14
+
15
+ books = load_dataset('FDSRashid/Hadith_info', data_files='Books.csv', token=Secret_token)['train'].to_pandas()
16
+ books.loc[:, 'book_type'] = books['book_type'].apply(lambda x: x.replace('"', '')[2:])
17
+ books.loc[:, 'Book_Name'] = books['Book_Name'].apply(lambda x: x.replace('"', ''))
18
+ books.loc[:, 'Author'] = books['Author'].apply(lambda x: x.replace('"', ''))
19
+ books = books.drop(columns = ['field5', 'field6', 'field7', 'field8'])
20
+
21
+
22
+ def book_retriever(name):
23
+ if 'ALL' in name:
24
+ return books
25
+ else:
26
+ full_names = name.replace(', ', '|').replace(',', '|')
27
+ return books[(books['Book_Name'].apply(lambda x: araby.strip_diacritics(x)).str.contains(araby.strip_diacritics(name), regex=True)) | (books['Author'].apply(lambda x: araby.strip_diacritics(x)).str.contains(araby.strip_diacritics(name), regex=True)) | (books['Book_ID'].astype(str).isin(full_names.split('|')))]
28
+
29
+
30
+ with gr.Blocks() as demo:
31
+ text_input = gr.Textbox()
32
+ text_output = gr.DataFrame(wrap=True)
33
+ text_button = gr.Button("Search")
34
+ text_button.click(narrator_retriever, inputs=text_input, outputs=text_output)
35
+
36
+ demo.launch()