import json import gradio as gr import pandas as pd from transformers import AutoTokenizer import torch from fastai.learner import load_learner df=pd.read_csv('healifyLLM_answer_dataset.csv') with open('question_labels.json', 'r') as f: questions_label = json.load(f) que_classes = list(questions_label.keys()) def answering(text): learner_inf = load_learner(fname="healifyLLM-stage4.pkl") percentage = learner_inf.blurr_predict(text)[0]['score']* 100 index = learner_inf.blurr_predict(text)[0]['class_index'] label = learner_inf.blurr_predict(text)[0]['class_labels'][index] result = df[df['label'] == label]['answer'] if percentage >= 35: return result.iloc[0] else: return "My knowledge is limited. Ask some other medical question." label = gr.components.Label(label="Answer") iface = gr.Interface(fn=answering,inputs="text", outputs=label, title="Disease QnA") iface.launch(inline=False)