import chainlit as cl @cl.on_chat_start async def start(): file = None # Wait for the user to upload a file while files == None: files = await cl.AskFileMessage( content="Please upload a text file to begin!", accept=["text/plain"] ).send() # Decode the file text_file = files[0] text = text_file.content.decode("utf-8") # Let the user know that the system is ready await cl.Message( content=f"`{text_file.name}` uploaded, it contains {len(text)} characters!" ).send()