Chainlit / chainlit

Build Conversational AI in minutes ⚡️
https://docs.chainlit.io
Apache License 2.0
7.13k stars 935 forks source link

Ask for a text file not working on docker image #740

Closed vivekjainmaiet closed 1 month ago

vivekjainmaiet commented 9 months ago

below code work locally but when running on docker container , it give error , Is there another way to access uploaded text file from user on docker container for further processing. Traceback (most recent call last): 2024-02-11 15:25:16 File "/home/user/.local/lib/python3.10/site-packages/chainlit/utils.py", line 39, in wrapper 2024-02-11 15:25:16 return await user_function(**params_values) 2024-02-11 15:25:16 File "/home/user/app/test.py", line 16, in start 2024-02-11 15:25:16 with open(text_file.path, "r", encoding="utf-8") as f: 2024-02-11 15:25:16 FileNotFoundError: [Errno 2] No such file or directory: 'clmtgqwa.txt'

import chainlit as cl @cl.on_chat_start async def start(): files = 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()

text_file = files[0]

with open(text_file.path, "r", encoding="utf-8") as f:
    text = f.read()

# Let the user know that the system is ready
await cl.Message(
    content=f"`{text_file.name}` uploaded, it contains {len(text)} characters!"
).send()
vivekjainmaiet commented 8 months ago

@willydouhard Could you please help on this. Latest version of Chainlit is not returning text_file.path , it is only returning file name.

willydouhard commented 8 months ago

Chainlit needs to write the file to the disk (once it is uploaded), maybe your setup is preventing that?

ModEnter commented 1 month ago

I'm closing this issue