gradio-app / gradio

Build and share delightful machine learning apps, all in Python. 🌟 Star to support our work!
http://www.gradio.app
Apache License 2.0
33.94k stars 2.58k forks source link

Gradio FileExplorer InvalidPathError #9918

Open alvadora opened 6 days ago

alvadora commented 6 days ago

Describe the bug

Trying to use FileExplorer to select a vector database for a RAG application leads to InvalidPathError. In the RAG, a user selects a particular folder and a function checks and displays what are the original files within the vector database so that they know what they are querying against.

This error did not occur while I was using gradio version 4.44.0 from a few months back. It had been about one month since I executed the .py file and when I did today (08/11/2024) it started showing the error and updating to gradio 5.5.0 did not change anything either.

Have you searched existing issues? 🔎

Reproduction

import gradio as gr
from langchain_chroma import Chroma
from langchain_community.embeddings import OllamaEmbeddings
embedding = OllamaEmbeddings(model = 'bge-large', model_kwargs = {'device':'gpu'})

def check_path(folder):
    vectorstore = Chroma(persist_directory = folder[0], embedding_function = embedding )
    metadata = vectorstore.get(include = ['metadatas'])
    metadata = metadata['metadatas']
    fp1 = []
    for file in metadata:
        fp1.append(file['source'])
    fp1 = list(dict.fromkeys(fp1))
    fp = []
    for file in fp1:
        fp.append(file.split('\\')[-1])
    return (fp)
checker = gr.Blocks()
with checker:
    folder = gr.FileExplorer(label='Select the existing database to update:', root_dir = 'C:/Users/thats/OneDrive/Documents/Python/RAG/')
    filepath_textbox = gr.Textbox(label='List of docs uploaded within this existing database:')
    folder.change(fn = check_path, inputs = folder, outputs = filepath_textbox)

demo = gr.TabbedInterface([checker], 
                          ["checker"])
if __name__ == "__main__":
    demo.launch(allowed_paths = ['C:/Users/thats/OneDrive/Documents/Python/RAG/']) 

Screenshot

No response

Logs

ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "C:\Users\thats\anaconda3\envs\py311\Lib\site-packages\uvicorn\protocols\http\httptools_impl.py", line 426, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\thats\anaconda3\envs\py311\Lib\site-packages\uvicorn\middleware\proxy_headers.py", line 84, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\thats\anaconda3\envs\py311\Lib\site-packages\fastapi\applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "C:\Users\thats\anaconda3\envs\py311\Lib\site-packages\starlette\applications.py", line 113, in __call__
    await self.middleware_stack(scope, receive, send)
  File "C:\Users\thats\anaconda3\envs\py311\Lib\site-packages\starlette\middleware\errors.py", line 187, in __call__
    raise exc
  File "C:\Users\thats\anaconda3\envs\py311\Lib\site-packages\starlette\middleware\errors.py", line 165, in __call__
    await self.app(scope, receive, _send)
  File "C:\Users\thats\anaconda3\envs\py311\Lib\site-packages\gradio\route_utils.py", line 796, in __call__
    await self.simple_response(scope, receive, send, request_headers=headers)
  File "C:\Users\thats\anaconda3\envs\py311\Lib\site-packages\gradio\route_utils.py", line 812, in simple_response
    await self.app(scope, receive, send)
  File "C:\Users\thats\anaconda3\envs\py311\Lib\site-packages\starlette\middleware\exceptions.py", line 62, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "C:\Users\thats\anaconda3\envs\py311\Lib\site-packages\starlette\_exception_handler.py", line 53, in wrapped_app
    raise exc
  File "C:\Users\thats\anaconda3\envs\py311\Lib\site-packages\starlette\_exception_handler.py", line 42, in wrapped_app
    await app(scope, receive, sender)
  File "C:\Users\thats\anaconda3\envs\py311\Lib\site-packages\starlette\routing.py", line 715, in __call__
    await self.middleware_stack(scope, receive, send)
  File "C:\Users\thats\anaconda3\envs\py311\Lib\site-packages\starlette\routing.py", line 735, in app
    await route.handle(scope, receive, send)
  File "C:\Users\thats\anaconda3\envs\py311\Lib\site-packages\starlette\routing.py", line 288, in handle
    await self.app(scope, receive, send)
  File "C:\Users\thats\anaconda3\envs\py311\Lib\site-packages\starlette\routing.py", line 76, in app
    await wrap_app_handling_exceptions(app, request)(scope, receive, send)
  File "C:\Users\thats\anaconda3\envs\py311\Lib\site-packages\starlette\_exception_handler.py", line 53, in wrapped_app
    raise exc
  File "C:\Users\thats\anaconda3\envs\py311\Lib\site-packages\starlette\_exception_handler.py", line 42, in wrapped_app
    await app(scope, receive, sender)
  File "C:\Users\thats\anaconda3\envs\py311\Lib\site-packages\starlette\routing.py", line 73, in app
    response = await f(request)
               ^^^^^^^^^^^^^^^^
  File "C:\Users\thats\anaconda3\envs\py311\Lib\site-packages\fastapi\routing.py", line 301, in app
    raw_response = await run_endpoint_function(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\thats\anaconda3\envs\py311\Lib\site-packages\fastapi\routing.py", line 212, in run_endpoint_function
    return await dependant.call(**values)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\thats\anaconda3\envs\py311\Lib\site-packages\gradio\routes.py", line 1295, in component_server
    return fn(body.data)
           ^^^^^^^^^^^^^
  File "C:\Users\thats\anaconda3\envs\py311\Lib\site-packages\gradio\components\file_explorer.py", line 178, in ls
    full_subdir_path = self._safe_join(subdirectory)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\thats\anaconda3\envs\py311\Lib\site-packages\gradio\components\file_explorer.py", line 209, in _safe_join
    x = safe_join(self.root_dir, combined_path)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\thats\anaconda3\envs\py311\Lib\site-packages\gradio\utils.py", line 1495, in safe_join
    raise InvalidPathError()
gradio.exceptions.InvalidPathError

System Info

Gradio Environment Information:
------------------------------
Operating System: Windows
gradio version: 5.5.0
gradio_client version: 1.4.2

Severity

Blocking usage of gradio

abidlabs commented 5 days ago

Seems related to https://github.com/gradio-app/gradio/issues/9715, cc @freddyaboulton