Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pickle
|
2 |
+
import os
|
3 |
+
|
4 |
+
|
5 |
+
print(os.getcwd())
|
6 |
+
fileobj=open("/home/user/app/embmmn7.obj","rb")
|
7 |
+
corpus_embeddings,corpus=pickle.load(fileobj)
|
8 |
+
fileobj.close()
|
9 |
+
from sentence_transformers import SentenceTransformer, util
|
10 |
+
import torch
|
11 |
+
|
12 |
+
embedder = SentenceTransformer("ramdane/jurimodel")
|
13 |
+
embedder.max_seq_length=510
|
14 |
+
def showrs(queries,number,id=0):
|
15 |
+
if(id==-1):
|
16 |
+
query_embedding = embedder.encode(queries, convert_to_tensor=True)
|
17 |
+
hits = util.semantic_search(query_embedding, corpus_embeddings, top_k=10)
|
18 |
+
hits = hits[0] #Get the hits for the first query
|
19 |
+
if(hits[number]['score']>0.2):
|
20 |
+
return corpus[hits[number]['corpus_id'] ]
|
21 |
+
else:
|
22 |
+
return "لم نتمكن من ايجاد النتيجة اما لعدم وجود الاجتهاد او لعدم كتابة جملة بحث مناسبة "
|
23 |
+
else:
|
24 |
+
chambres=[["العقارية", "الغرفة العقارية"," العقارية"],["المدنية","الغرفة المدنية ","غرفة المدنية "],["الاجتماعية","الغرفة الاجتماعية","الإجتماعية" ], ["الجنح","الجنح","جنح ومخالفت" ], ["الجنائية","جنائية","الجنائية"],["شؤون الاسرة","شؤون الأسرة","الاحوال الشخصية","المواريث","الأحوال الشخصية"],["التجارية ","التجارية ","التجارية","تجارية","البحرية"]]
|
25 |
+
phrases_to_search = chambres[id]
|
26 |
+
|
27 |
+
corpusf = []
|
28 |
+
corpus_embeddingsf = []
|
29 |
+
|
30 |
+
for i, text in enumerate(corpus):
|
31 |
+
found = any(phrase in text for phrase in phrases_to_search)
|
32 |
+
if found:
|
33 |
+
corpusf.append(text)
|
34 |
+
corpus_embeddingsf.append(corpus_embeddings[i])
|
35 |
+
query_embedding = embedder.encode(queries, convert_to_tensor=True)
|
36 |
+
hits = util.semantic_search(query_embedding, corpus_embeddingsf, top_k=10)
|
37 |
+
hits = hits[0]
|
38 |
+
|
39 |
+
return corpusf[hits[number]['corpus_id'] ]
|
40 |
+
import gradio as gr
|
41 |
+
|
42 |
+
|
43 |
+
# Define a dictionary to map text labels to numbers
|
44 |
+
room_options = {
|
45 |
+
"الكل": -1,
|
46 |
+
"الغرفة العقارية": 0,
|
47 |
+
"الغرفة المدنية": 1,
|
48 |
+
"الغرفة الاجتماعية": 2,
|
49 |
+
"الغرفة الجنح والمخالفات": 3,
|
50 |
+
"الغرفة الحنائية": 4,
|
51 |
+
"الغرفة شؤون الاسرة والمواريث": 5,
|
52 |
+
"الغرفة التجارية": 6,
|
53 |
+
}
|
54 |
+
|
55 |
+
def greet_user(name,numbers,num):
|
56 |
+
# Extract the selected number based on the selected room
|
57 |
+
number =num
|
58 |
+
|
59 |
+
return showrs(name,int(numbers),int(number))
|
60 |
+
|
61 |
+
# Create a list of room options for the dropdown
|
62 |
+
room_choices = list(room_options.keys())
|
63 |
+
|
64 |
+
app = gr.Interface(
|
65 |
+
fn=greet_user,
|
66 |
+
inputs=[gr.Textbox(label="ادخل كلمات البحث"),gr.Number(label="الترتيب"),gr.Number(label="اختر الغرفة")],
|
67 |
+
outputs=gr.TextArea(label="Result")
|
68 |
+
)
|
69 |
+
app.launch()
|