OmarElSayed commited on
Commit
559e876
1 Parent(s): 25c4703

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -10
app.py CHANGED
@@ -4,9 +4,9 @@ import gradio as gr
4
  import re
5
 
6
 
7
- dataset = pd.read_excel('Dataset-Verse-by-Verse.xlsx')
8
  dataset.rename(columns={'ArabicText': 'text'}, inplace=True)
9
- nlp = spacy.load('aravec_model')
10
  all_docs = [nlp(doc) for doc in dataset['text']]
11
 
12
  def clean_text(text):
@@ -31,21 +31,31 @@ def get_similar_sentences(text):
31
  text = clean_text(text)
32
  ref_sentence = nlp(text)
33
  similar_sentences = []
34
- for i,doc in enumerate(all_docs):
35
- similar_sentences.append((doc, ref_sentence.similarity(doc) , i))
36
- similar_sentences.sort(key=lambda x: x[1], reverse=True)
 
 
 
 
 
 
 
 
 
 
 
37
  top_10 = similar_sentences[:10]
38
- # add the surahnamearabic to text
39
- return dict(zip([' [ ' + dataset['SurahNameArabic'][i] + ' ] ' + doc.text for doc, _, i in top_10], [similarity for _, similarity, _ in top_10]))
40
 
41
  text_input = gr.inputs.Textbox(lines = 1 , label = "Enter a Quran Verse" )
42
 
43
- label = gr.outputs.Label()
44
  examples = ['الحمدلله رب العالمين',
45
  'مثلهم كمثل الذي استوقد نارًا فلما أضاءت ما حوله ذهب الله بنورهم وتركهم في ظلماتٍ لا يبصرون',
46
  'إن الذين كفروا سواء عليهم أأنذرتهم أم لم تنذرهم لا يؤمنون',
47
  'ونادى أصحاب الجنة أصحاب النار أن قد وجدنا ما وعدنا ربنا حقا فهل وجدتم ما وعد ربكم حقا ۖ قالوا نعم ۚ فأذن مؤذن بينهم أن لعنة الله على الظالمين'
48
  ]
49
 
50
- intf = gr.Interface(fn = get_similar_sentences , inputs = text_input , outputs = "json" , examples=examples )
51
- intf.launch()
 
4
  import re
5
 
6
 
7
+ dataset = pd.read_excel('/content/test/Dataset-Verse-by-Verse.xlsx')
8
  dataset.rename(columns={'ArabicText': 'text'}, inplace=True)
9
+ nlp = spacy.load('/content/test/aravec_model')
10
  all_docs = [nlp(doc) for doc in dataset['text']]
11
 
12
  def clean_text(text):
 
31
  text = clean_text(text)
32
  ref_sentence = nlp(text)
33
  similar_sentences = []
34
+ for i, doc in enumerate(dataset['text']):
35
+ similarity_score = ref_sentence.similarity(nlp(doc))
36
+ similar_sentence = doc
37
+ surah_name = dataset['SurahNameArabic'][i]
38
+ ayah_no = dataset['AyahNo'][i]
39
+ surah_no = dataset['SurahNo'][i]
40
+ similar_sentences.append({
41
+ "similar_sentence": similar_sentence,
42
+ "similarity_score": similarity_score,
43
+ "surahName": surah_name,
44
+ "AyahNo": ayah_no,
45
+ "SurahNumber" : surah_no
46
+ })
47
+ similar_sentences.sort(key=lambda x: x['similarity_score'], reverse=True)
48
  top_10 = similar_sentences[:10]
49
+ return top_10
 
50
 
51
  text_input = gr.inputs.Textbox(lines = 1 , label = "Enter a Quran Verse" )
52
 
53
+ output_text = gr.outputs.Textbox(label="Output Text")
54
  examples = ['الحمدلله رب العالمين',
55
  'مثلهم كمثل الذي استوقد نارًا فلما أضاءت ما حوله ذهب الله بنورهم وتركهم في ظلماتٍ لا يبصرون',
56
  'إن الذين كفروا سواء عليهم أأنذرتهم أم لم تنذرهم لا يؤمنون',
57
  'ونادى أصحاب الجنة أصحاب النار أن قد وجدنا ما وعدنا ربنا حقا فهل وجدتم ما وعد ربكم حقا ۖ قالوا نعم ۚ فأذن مؤذن بينهم أن لعنة الله على الظالمين'
58
  ]
59
 
60
+ intf = gr.Interface(fn = get_similar_sentences , inputs = text_input , outputs = output_text , examples=examples )
61
+ intf.launch(debug = True)