custom module function call referenced ones , but it gets called multiple times

I have a streamlit based question/answering project, which has following structure.

files/loader.py
files/pdf.py
files/database.py
files/query.py
app.py

Modules called by in order such as:

app.py(streamlit chatbot functionality built inside of this file)>>>pdf.py(one upload file streamlit functions to upload pdf and mp3 files and extend them inside of list)>>> loader.py(has code of to process every file kind and return data to pdf.py module)
pdf.py>> database.py(to save procecesed data in a chromadb)
app.py>> query.py(Retrieve data from chromadb and has function to answer queries and return answer by app.py)

app.py sample is:

    import different python modules
    from files import pdf
    other funcitions to process queries:
    class single_ques:
     def __init__(self):
     #some code
    class multiple_ques:
       def __init--(self):
     #some code
    
     
    def main():
      pdf.main()   # Here i called pdf module main function, which i want to be called only once
      if button==single_ques:
         single_ques()
      if button==multiple_ques:
         multiple_ques()

if __name__=='__main__;
main()

pdf.py sample is:

    class doc:
      def __init__(self,path)
        self.document = self.load()
            if self.path.endswith(('.txt','.docx','.pdf')):
                self.chunks = self.chunking()
      def load(self):
        if self.path.endswith(.txt):
                #some code to process it from module in loder.py
           # same way for other file types
        def chunk:
           #chunking function
    
    def main:
      names=[]
            uploaded_files=st.file_uploader("Choose data files", accept_multiple_files=True)
            
            if uploaded_files:
                for up in uploaded_files:
                     names.append(up.name)
                    # with open(up.name,mode='wb') as w:
                    #     w.write(up.getvalue())
                if  names:
                    d={}
                    
            
                    for up in  names:
                        if up not in d:
                            RAG = doc(up)
                            documents = doc.load()
                            d[up]=True
                            uploaded_files=None
if __name__=='__main__;
main()

So when instead of uploading files , i provide hardcoded files addresses and run pdf.py files separately,means i dont call pdf.py module in app.py, ebverything work as expacted.
But i want to upload different files every time , if i run app.py, so it should create new database.
Problem is whenever i click some button or enter queries on alreday running chat bot, files processing repeated, and database got replaced. it keeps on process already uploaded files on each operation, unnecessary. i want pdf.py modules should be called only once, not for every queries file processing function be called.

Please help

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật