Spaces:
Running
Running
File size: 875 Bytes
fcadab7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import gradio as gr
import pandas as pd
from sentence_transformers import SentenceTransformer, util
# Load data
df = pd.read_csv("fatwas.csv")
model = SentenceTransformer("paraphrase-multilingual-MiniLM-L12-v2")
embeddings = model.encode(df["question"].tolist(), convert_to_tensor=True)
def search_fatwa(query):
query_embedding = model.encode(query, convert_to_tensor=True)
scores = util.pytorch_cos_sim(query_embedding, embeddings)[0]
top_idx = int(scores.argmax())
return {
"question": df.iloc[top_idx]["question"],
"answer": df.iloc[top_idx]["answer"],
"link": df.iloc[top_idx]["link"]
}
iface = gr.Interface(
fn=search_fatwa,
inputs="text",
outputs="json",
allow_flagging="never",
title="Fatwa Search",
description="Ask a question and receive a relevant fatwa with a verified link"
)
iface.launch()
|