question answering model
Browse files1234567891011121314151617181920212223242526272829import pandas as pdfrom sentence_transformers import SentenceTransformer, utilimport gradio
PATH_TO_FILE = 'cabot_dataset_def_csv.csv'df = pd.read_csv(PATH_TO_FILE, sep=';')df.drop_duplicates(inplace=True, ignore_index=True)
model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
def run_question(domanda): somme = [] for jdx, j in enumerate(list(df.Question)): somme.append(float(util.pytorch_cos_sim( model.encode(list(df.Question)[jdx], convert_to_tensor=True), model.encode(domanda, convert_to_tensor=True)))) if round(max(somme)*100) < 70: return 'Sorry, could you paraphrase your question? I quide didn\'t catch that...' else: return df.loc[somme.index(max(somme)), 'Answer']
gradio.Interface(run_question, "text", "text", title='Introducing C.A.BOT', description='This is Cabot, the Consular Affairs bot. Give it a try asking').launch()
app.pyAdded+29