Files
wehub-resource-sync b7f52be4c9
CI / Run CI (push) Has been cancelled
CI / check-backend (push) Has been cancelled
CI / check-frontend (push) Has been cancelled
CI / tests (push) Has been cancelled
CI / e2e-tests (push) Has been cancelled
Copilot Setup Steps / copilot-setup-steps (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:48:47 +08:00

36 lines
1.2 KiB
Python

import aiofiles
import chainlit as cl
@cl.on_chat_start
async def start():
files = await cl.AskFileMessage(
content="Please upload a text file to begin!", accept=["text/plain"]
).send()
txt_file = files[0]
async with aiofiles.open(txt_file.path, encoding="utf-8") as f:
content = await f.read()
await cl.Message(
content=f"`Text file {txt_file.name}` uploaded, it contains {len(content)} characters!"
).send()
files = await cl.AskFileMessage(
content="Please upload a python file to begin!",
accept={
"text/plain": [".py", ".txt"],
# Some browser / os report it as text/plain but some as text/x-python when doing drag&drop
"text/x-python": [".py"],
# Or even as application/octet-stream when using the select file dialog
"application/octet-stream": [".py"],
},
).send()
py_file = files[0]
async with aiofiles.open(py_file.path, encoding="utf-8") as f:
content = await f.read()
await cl.Message(
content=f"`Python file {py_file.name}` uploaded, it contains {len(content)} characters!"
).send()