I created a retrieval Chatbot which works fine with a json file.. The challenge I'm having is retrieving values from a csv file. For example a user wants to retrieve rows/columns with a particular heading. They are supposed to enter a numerical prompt (eg. 1) which searches the dB and returns results based on the item the user wants found. Everything works as planned out but on the cmd.. The results (prompts, outputs) refuse to display on the frontend (flask).
All I want is for the prompts to display on the frontend for user interaction. I've tried different things and no positive results yet . function to search csv file based on columns if, elif to differentiate between columns searches code working fine in cmd nothing from the frontend.
All I want is for the prompts to display on the frontend for user interaction. I've tried different things and no positive results yet . function to search csv file based on columns if, elif to differentiate between columns searches code working fine in cmd nothing from the frontend
#routes.py
def searchByProductDesc():
product=input('Enter food item name\n')
csv_file=csv.reader(open('chatbot_codes\GeneralProductPricing.csv','r'))
for row in csv_file:
if product==row[2]:
c=str(print(row))
return c
def searchByDate():
product=input('Enter observed date of food prices\n')
csv_file=csv.reader(open('chatbot_codes\GeneralProductPricing.csv','r'))
for row in csv_file:
if product==row[0]:
c=str(print(row))
return c
def searchByLocation():
product=input('Enter the location of the market\n')
csv_file=csv.reader(open('chatbot_codes\GeneralProductPricing.csv','r'))
for row in csv_file:
if product==row[4]:
c=str(print(row))
return c
def searchByMarketName():
product=input('Enter the name of the market\n')
csv_file=csv.reader(open('chatbot_codes\GeneralProductPricing.csv','r'))
for row in csv_file:
if product==row[5]:
c=str(print(row))
return c
def get_response(return_list,intents_json,text):
if len(return_list)==0:
tag='noanswer'
else:
tag=return_list[0]['intent']
if tag=='prices':
r = int(input('For food prices: \n Enter 1 to search by product name (eg. Bitterleaf) \n Enter 2 to search by observed date (eg. 03/03/2023) \n Enter 3 to search by market location (eg. Wuse, FCT Abuja) \n Enter 4 to search by market name (eg. Wuse Market) \n You may proceed... '))
if r==1:
x = searchByProductDesc()
return x, 'prices'
elif r==2:
x = searchByDate()
return x, 'prices'
elif r==3:
x = searchByLocation()
return x, 'prices'
elif r==4:
x = searchByMarketName()
return x, 'prices'
else:
x = 'Sorry, invalid input!'
print(x)
return x, 'prices'
@app.route("/get")
def chatbot():
userText = request.args.get('msg')
resp=response(userText)
return resp