Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -4,18 +4,26 @@ from sentence_transformers import SentenceTransformer, util
|
|
4 |
|
5 |
# Load data
|
6 |
df = pd.read_excel("IslamWeb_output.xlsx")
|
7 |
-
|
8 |
model = SentenceTransformer("paraphrase-multilingual-MiniLM-L12-v2")
|
9 |
embeddings = model.encode(df["question"].tolist(), convert_to_tensor=True)
|
10 |
|
|
|
|
|
11 |
def search_fatwa(query):
|
12 |
query_embedding = model.encode(query, convert_to_tensor=True)
|
13 |
scores = util.pytorch_cos_sim(query_embedding, embeddings)[0]
|
14 |
top_idx = int(scores.argmax())
|
|
|
|
|
|
|
15 |
return {
|
16 |
-
"
|
17 |
-
"
|
18 |
-
"
|
|
|
|
|
|
|
19 |
}
|
20 |
|
21 |
iface = gr.Interface(
|
|
|
4 |
|
5 |
# Load data
|
6 |
df = pd.read_excel("IslamWeb_output.xlsx")
|
7 |
+
df2 = pd.read_excel("JordanFatwas_all.xlsx")
|
8 |
model = SentenceTransformer("paraphrase-multilingual-MiniLM-L12-v2")
|
9 |
embeddings = model.encode(df["question"].tolist(), convert_to_tensor=True)
|
10 |
|
11 |
+
embeddings2 = model.encode(df2["question"].tolist(), convert_to_tensor=True)
|
12 |
+
|
13 |
def search_fatwa(query):
|
14 |
query_embedding = model.encode(query, convert_to_tensor=True)
|
15 |
scores = util.pytorch_cos_sim(query_embedding, embeddings)[0]
|
16 |
top_idx = int(scores.argmax())
|
17 |
+
|
18 |
+
scores2 = util.pytorch_cos_sim(query_embedding, embeddings2)[0]
|
19 |
+
top_idx2 = int(scores2.argmax())
|
20 |
return {
|
21 |
+
"question1": df.iloc[top_idx]["question"],
|
22 |
+
"answer1": df.iloc[top_idx]["answer"],
|
23 |
+
"link1": df.iloc[top_idx]["link"],
|
24 |
+
"question2": df2.iloc[top_idx2]["question"],
|
25 |
+
"answer2": df2.iloc[top_idx2]["answer"],
|
26 |
+
"link2": df2.iloc[top_idx2]["link"],
|
27 |
}
|
28 |
|
29 |
iface = gr.Interface(
|