diff --git a/pyproject.toml b/pyproject.toml index 44531eb..ac73d85 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,7 +35,7 @@ dependencies = [ "aiosqlite>=0.20.0", "asyncpg>=0.30.0", "boto3>=1.35.92", - "chainlit>=2.0.2", + "chainlit>=2.0.3", "huggingface-hub>=0.27.0", "langchain>=0.3.13", "langchain-community>=0.3.13", @@ -46,11 +46,15 @@ dependencies = [ "prisma>=0.15.0", "psycopg2-binary>=2.9.10", "pydantic-settings>=2.7.0", + "yt-dlp>=2025.1.12", ] [tool.uv] default-groups = ["dev", "doc", "test"] +[tool.uv.sources] +chainlit = { git = "https://github.com/Chainlit/chainlit.git", subdirectory = "backend" } + [tool.pytest.ini_options] minversion = "7.0.0" diff --git a/src/podflix/gui/audio.py b/src/podflix/gui/audio.py index 54bec79..5302fd3 100644 --- a/src/podflix/gui/audio.py +++ b/src/podflix/gui/audio.py @@ -6,6 +6,7 @@ from langchain_community.chat_message_histories import ChatMessageHistory from langfuse.callback import CallbackHandler as LangfuseCallbackHandler from literalai.helper import utc_now +from loguru import logger # noqa: F401 from podflix.env_settings import env_settings from podflix.graph.podcast_rag import compiled_graph @@ -61,13 +62,18 @@ async def on_chat_start(): # Wait for the user to upload a file while files is None: - files = await cl.AskFileMessage( + ask_file_message = cl.AskFileMessage( content="Please upload a audio file to start the conversation", accept=["audio/*"], max_files=1, max_size_mb=50, timeout=360, - ).send() + ) + files = await ask_file_message.send() + + # await ask_file_message.remove() + # ask_file_message.content = "DUMMY" + # await ask_file_message.update() file = files[0] @@ -80,7 +86,7 @@ async def on_chat_start(): # NOTE: Workaround to get s3 url of the uploaded file in the current thread thread_id = get_current_chainlit_thread_id() - audio_url = await get_read_url_of_file(thread_id=thread_id, file_name=file.name) + audio_url = await get_read_url_of_file(thread_id=thread_id, file_id=file.id) # Create audio element with transcript and segments audio_element = cl.CustomElement( diff --git a/src/podflix/utils/chainlit_utils/data_layer.py b/src/podflix/utils/chainlit_utils/data_layer.py index ca76e4d..26e75c3 100644 --- a/src/podflix/utils/chainlit_utils/data_layer.py +++ b/src/podflix/utils/chainlit_utils/data_layer.py @@ -155,7 +155,7 @@ async def get_element_url( return element_dict.url -async def get_read_url_of_file(thread_id: str, file_name: str) -> str: +async def get_read_url_of_file(thread_id: str, file_id: str) -> str: """Retrieve the URL for accessing an file in a thread. Examples: @@ -165,7 +165,7 @@ async def get_read_url_of_file(thread_id: str, file_name: str) -> str: Args: thread_id: The unique identifier of the thread containing the file. - file_name: The full name of the the file to retrieve, included the file extension. + file_id: The file id of the file to retrieve. Returns: str: The S3 URL string of the file. @@ -178,7 +178,7 @@ async def get_read_url_of_file(thread_id: str, file_name: str) -> str: if cl_data_layer.storage_client is None: raise ValueError("S3 storage client not set in data layer.") - object_key = f"threads/{thread_id}/files/{file_name}" + object_key = f"threads/{thread_id}/files/{file_id}" return await cl_data_layer.storage_client.get_read_url(object_key=object_key) diff --git a/uv.lock b/uv.lock index 5e25bf8..735b3cb 100644 --- a/uv.lock +++ b/uv.lock @@ -290,8 +290,8 @@ wheels = [ [[package]] name = "chainlit" -version = "2.0.2" -source = { registry = "https://pypi.org/simple" } +version = "2.0.3" +source = { git = "https://github.com/Chainlit/chainlit.git?subdirectory=backend#fb1e646110978094fc5c92ae6020346b5f8da162" } dependencies = [ { name = "aiofiles" }, { name = "asyncer" }, @@ -316,10 +316,6 @@ dependencies = [ { name = "uvicorn" }, { name = "watchfiles" }, ] -sdist = { url = "https://files.pythonhosted.org/packages/42/33/c9a2060f499ef2c196405f80be9e03fa212e56307e0345fffacc5641fb03/chainlit-2.0.2.tar.gz", hash = "sha256:ec60a83884029dfa9e2f8215a81d99627c465407ac33ef37b19c7d515d9c0e7a", size = 4637820 } -wheels = [ - { url = "https://files.pythonhosted.org/packages/72/e4/563dbf1bc21dcda915d15ea27d739a8afff5ee861f40bc4adb67c33c56cd/chainlit-2.0.2-py3-none-any.whl", hash = "sha256:58fe3da65e892058a8e8ad97bb9dc4177173857d8c288a3de4a73271fc1b18be", size = 4704765 }, -] [[package]] name = "charset-normalizer" @@ -1806,6 +1802,7 @@ dependencies = [ { name = "prisma" }, { name = "psycopg2-binary" }, { name = "pydantic-settings" }, + { name = "yt-dlp" }, ] [package.dev-dependencies] @@ -1834,7 +1831,7 @@ requires-dist = [ { name = "aiosqlite", specifier = ">=0.20.0" }, { name = "asyncpg", specifier = ">=0.30.0" }, { name = "boto3", specifier = ">=1.35.92" }, - { name = "chainlit", specifier = ">=2.0.2" }, + { name = "chainlit", git = "https://github.com/Chainlit/chainlit.git?subdirectory=backend" }, { name = "huggingface-hub", specifier = ">=0.27.0" }, { name = "langchain", specifier = ">=0.3.13" }, { name = "langchain-community", specifier = ">=0.3.13" }, @@ -1845,6 +1842,7 @@ requires-dist = [ { name = "prisma", specifier = ">=0.15.0" }, { name = "psycopg2-binary", specifier = ">=2.9.10" }, { name = "pydantic-settings", specifier = ">=2.7.0" }, + { name = "yt-dlp", specifier = ">=2025.1.12" }, ] [package.metadata.requires-dev] @@ -2919,6 +2917,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/f5/4b/a06e0ec3d155924f77835ed2d167ebd3b211a7b0853da1cf8d8414d784ef/yarl-1.18.3-py3-none-any.whl", hash = "sha256:b57f4f58099328dfb26c6a771d09fb20dbbae81d20cfb66141251ea063bd101b", size = 45109 }, ] +[[package]] +name = "yt-dlp" +version = "2025.1.12" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/8c/16/69ca019a8346313ea141c24429322d479b28b15e8d7a23af03b0065767f1/yt_dlp-2025.1.12.tar.gz", hash = "sha256:8e7e246e2a5a2cff0a9c13db46844a37a547680702012058c94ec18fce0ca25a", size = 2916928 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/f3/9d/782c67465798478b3f8cf8c72da771e1eb0956e13b820f862b35de66d4a7/yt_dlp-2025.1.12-py3-none-any.whl", hash = "sha256:f7ea19afb64f8e457a1b9598ddb67f8deaa313bf1d57abd5612db9272ab10795", size = 3178322 }, +] + [[package]] name = "zipp" version = "3.21.0"