File size: 1,576 Bytes
f972310
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
abc88d8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from datetime import datetime
#from pypdf import PdfReader

from langchain.chains import LLMChain, RetrievalQA












#def pdf_to_text(pdf_file,name='Readme'):
#    """
#    Function that reads a pdf file and saves it to txt format.
#    ---------------------------------------------------------
#    Parameters:
#        pdf_file: str.
#            contains file name or path to the file in .pdf format
#        name: str.
#            contains the name to save the .txt file with
#            Default: Readme.txt
#    ---------------------------------------------------------
#    Returns:
#        testo: list.
#            list with the text extracted on each page of the .pdf file
#    ---------------------------------------------------------
#    """
#    testo=[]
#    reader=PdfReader(pdf_file)
#    for i in range(0,len(reader.pages)):
#        text = reader.pages[i].extract_text()
#        testo.append(text)
#    try:
#        with open(f'{name}.txt', 'w', encoding='utf-8') as f:
#            f.writelines(testo)
#        f.close()
#    except Exception as e:
#        print(f"passed on exception because {e}")
#    return testo


def today():
    today= datetime.today()
    return today.strftime('%Y-%m-%d %H:%M:%S')

def ask(query):
  result = RetrievalQA({"query": query})
  return result['result']

def write_text_file(content, file_path):
    try:
        with open(file_path, 'w') as file:
            file.write(content)
        return True
    except Exception as e:
        print(f"Error occurred while writing the file: {e}")
        return False