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 line2345567891011121213141415161717181920202122232422232425262728293031321 unmodified linefrom sentence_transformers import SentenceTransformer, utilimport gradio
PATH_TO_FILE = 'cabot_dataset_def_csv.csv'PATH_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): somme = [] similarities = [] for jdx, j in enumerate(list(df.Question)): somme.append(float(util.pytorch_cos_sim( 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(somme)*100) < 70: 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[somme.index(max(somme)), 'Answer'] return df.loc[similarities.index(max(similarities)), '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()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