def simple_upload(request): try: if request.method == 'POST' and request.FILES['myfile']: myfile = request.FILES['myfile'] query = request.POST['query'] df = pd.read_csv(myfile) agent = Agent(df) database_result = agent.query_db(query) database_query = agent.get_query(question=query) return render(request, 'agent/simple_upload.html', { 'database_result': database_result, 'database_query': database_query }) return render(request, 'agent/simple_upload.html') except MultiValueDictKeyError: database_result = "Please Upload a CSV" return render(request, 'agent/simple_upload.html',{ 'database_result':database_result })
def get_results(self, text, csv_dir=None, schema_dir=None): """ Parameters ---------- text : `str` or `pathlib.Path` object. Input text to be processed or path to file(.txt/.docx) containing textual information. csv_path : `str` or `pathlib.Path` object, absolute path to folder containing all input files. Optional schema_path: `str` or `pathlib.Path` object, path to folder containing `json` schemas of input files. If not specified, auto-generated schema will be used.Optional Returns ------- valmaps : `dict` Maps questions with generated answers. """ valmaps = {} if os.path.isfile(text): text = self.__text_process(text) if csv_dir: questions = self.get_questions(text, csv=True) agent = Agent(csv_dir, schema_dir) for q in questions: try: res = agent.query_db(q) valmaps[q] = res except: pass else: questions = self.get_questions(text) for q in questions: valmaps[q] = qa(text, q) return valmaps