second update app.py
Browse fileschanged variable name "somme" to "similarities" to be more explicit. Better formatted the description. Added more explicative input and audio labels.
1 unmodified line23456789101112131415161718192021222324252627281 unmodified linefrom sentence_transformers import SentenceTransformer, utilimport gradioPATH_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(Question):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(Question, convert_to_tensor=True))))if round(max(somme)*100) < 70:return 'I\'m sorry, I\'m not sure I understood your question. Could you try again?'else:return df.loc[somme.index(max(somme)), 'Answer']gradio.Interface(run_question, "text", "text",title='Introducing C.A.BOT',description='Hi! This is Cabot, the Consular Affairs bot.\nI will help you answer your questions about the Citizen Services that you can request at the Consular Sections within U.S. Embassy Rome.').launch()1 unmodified line2345678910111213141516171819202122232425262728293031321 unmodified linefrom sentence_transformers import SentenceTransformer, utilimport gradioPATH_TO_FILE = 'cabot_qa.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(Question):similarities = []for jdx, j in enumerate(list(df.Question)):similarities.append(float(util.pytorch_cos_sim(model.encode(list(df.Question)[jdx], convert_to_tensor=True),model.encode(Question, convert_to_tensor=True))))if round(max(similarities)*100) < 70:return 'I\'m sorry, I\'m not sure I understood your question. Could you try again?'else:return df.loc[similarities.index(max(similarities)), 'Answer']description = """Hi! I'm is Cabot, the Consular Affairs bot.<br>I will answer your questions about the Citizen Services that you can request at the Consular Sections within U.S. Embassy Rome."""gradio.Interface(run_question,title='Introducing C.A.BOT',description=description,inputs=gradio.Textbox(label="Type your question here!"),outputs=gradio.Textbox(label="Answer")).launch()
app.py+12-8