|
|
import gradio as gr |
|
|
from sentence_transformers import SentenceTransformer, util |
|
|
import pandas as pd |
|
|
import torch |
|
|
|
|
|
|
|
|
model = SentenceTransformer("yazied49/NAdine3") |
|
|
|
|
|
|
|
|
df = pd.read_csv("final_special_needs_qa.csv") |
|
|
questions = df["question"].tolist() |
|
|
answers = df["answer"].tolist() |
|
|
question_embeddings = model.encode(questions, convert_to_tensor=True) |
|
|
|
|
|
def get_answer(user_input): |
|
|
input_embedding = model.encode(user_input, convert_to_tensor=True) |
|
|
cos_scores = util.pytorch_cos_sim(input_embedding, question_embeddings)[0] |
|
|
best_match_idx = torch.argmax(cos_scores).item() |
|
|
return answers[best_match_idx] |
|
|
|
|
|
iface = gr.Interface( |
|
|
fn=get_answer, |
|
|
inputs=gr.Textbox(lines=2, placeholder="اكتب سؤالك هنا..."), |
|
|
outputs="text", |
|
|
title="المساعد الطبي لذوي الاحتياجات الخاصة", |
|
|
description="اسأل أي سؤال متعلق بذوي الاحتياجات الخاصة وسنحاول مساعدتك." |
|
|
) |
|
|
|
|
|
iface.launch() |
|
|
|