gradio-app/gradio

IsADirectoryError: [Errno 21] Is a directory: '/xxx'

Closed this issue · 4 comments

Describe the bug

This is an occasional problem,when i send a request and wait for the response, processing_utils.py throw this error,The directory structure of this demo is / gradio-demo/demo.py

Have you searched existing issues? 🔎

  • I have searched and found no existing issues

Reproduction

import gradio as gr
import requests
import json
import  uuid
from PIL import Image
from io import BytesIO
import os
os.environ["GRADIO_CACHE_EXAMPLES"] = "lazy"

url = "http://xxxx/api/v1/comfy"


def flip_sdxl_variation(input_img, prompt, ratio, batch_count):
    try:
        file_name = f"aigc/{uuid.uuid4()}.png"
        image = Image.fromarray(input_img)
        image_byte_array = BytesIO()
        image.save(image_byte_array, format='JPEG')
        image_byte_array.seek(0)
        img_url = aliyunoss.put_object(file_name, image_byte_array)
        # remote_url = ""
        remote_url = url + "/images/create"
        data = {
            "initImage": img_url,
            "prompt": prompt,
            "ratio": ratio,
            "batchCount": int(batch_count)
        }
        res = requests.post(remote_url, json=data,timeout=360)
        images = []
        if res.status_code == 200:
            res_data = res.json()
            images = res_data["data"]["images"]
        return images
    except Exception as e:
        return str(e)



with gr.Blocks() as demo:
    with gr.Tab("imgVariation"):
        with gr.Row():
            variation_sdxl_input = gr.Image()
            variation_sdxl_output = gr.Gallery(allow_preview=True,preview=True,columns=4)
        variation_sdxl_button = gr.Button("submit",variant='primary')

    with gr.Accordion("params", open=True):
        text_input = gr.Textbox(label="prompt")
        ratio = gr.Radio(label="ratio",choices=["1:1", "3:4", "4:3", "16:9","9:16"])
        batch_count = gr.Number(label="number",value=1, minimum=1, maximum=10)

    variation_sdxl_button.click(flip_sdxl_variation,
                                inputs=[variation_sdxl_input, text_input, ratio, batch_count],
                                outputs=variation_sdxl_output,
                                trigger_mode="once"
                                )
if __name__ == "__main__":
    demo.launch(server_name="0.0.0.0",server_port=8000)

Screenshot

No response

Logs

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/gradio/queueing.py", line 527, in process_events
    response = await route_utils.call_process_api(
  File "/usr/local/lib/python3.8/site-packages/gradio/route_utils.py", line 270, in call_process_api
    output = await app.get_blocks().process_api(
  File "/usr/local/lib/python3.8/site-packages/gradio/blocks.py", line 1897, in process_api
    data = await self.postprocess_data(fn_index, result["prediction"], state)
  File "/usr/local/lib/python3.8/site-packages/gradio/blocks.py", line 1725, in postprocess_data
    outputs_cached = await processing_utils.async_move_files_to_cache(
  File "/usr/local/lib/python3.8/site-packages/gradio/processing_utils.py", line 479, in async_move_files_to_cache
    return await client_utils.async_traverse(
  File "/usr/local/lib/python3.8/site-packages/gradio_client/utils.py", line 1008, in async_traverse
    new_obj.append(await async_traverse(item, func, is_root))
  File "/usr/local/lib/python3.8/site-packages/gradio_client/utils.py", line 1003, in async_traverse
    new_obj[key] = await async_traverse(value, func, is_root)
  File "/usr/local/lib/python3.8/site-packages/gradio_client/utils.py", line 999, in async_traverse
    return await func(json_obj)
  File "/usr/local/lib/python3.8/site-packages/gradio/processing_utils.py", line 453, in _move_to_cache
    temp_file_path = await block.async_move_resource_to_block_cache(
  File "/usr/local/lib/python3.8/site-packages/gradio/blocks.py", line 286, in async_move_resource_to_block_cache
    temp_file_path = processing_utils.save_file_to_cache(
  File "/usr/local/lib/python3.8/site-packages/gradio/processing_utils.py", line 257, in save_file_to_cache
    temp_dir = hash_file(file_path)
  File "/usr/local/lib/python3.8/site-packages/gradio/processing_utils.py", line 189, in hash_file
    with open(file_path, "rb") as f:
IsADirectoryError: [Errno 21] Is a directory: '/gradio-demo'

System Info

gradio==4.31.0

Severity

Facing the same issue as well.

Hi @yangmingbai - is it possible the api is returning an empty string in res_data["data"]["images"]?

@sachin-aakash , are you using the same demo?

@freddyaboulton,Thanks,This is an error raised by requests, requests.Post throw an error "Connection aborted.RemoteDisconnected('Remote end closed connection without response')", Thanks again!

Hi @yangmingbai - is it possible the api is returning an empty string in res_data["data"]["images"]?

@sachin-aakash , are you using the same demo?

No, here is my code and the error -

def pdf_process(file):
    pdf_file_path = file
    dir_location = os.path.dirname(pdf_file_path[0])
    filename = os.path.split(pdf_file_path[0])
    pdf_name = filename[1].split(".pdf")[0]
    command = ["node", "pdfToImageDynamic.js", quote(pdf_file_path[0]), dir_location, pdf_name]
    subprocess.run(command, check=True)
    image_name = os.path.join(dir_location,pdf_name + ".1.png")
    try:
        elements = partition_image(filename=image_name, strategy=strategy,infer_table_structure=True)
        elements_to_json(elements, filename=f"{image_name}.json")
        output_final =  process_json_file(f"{image_name}.json",dir_location,pdf_name)
        print(output_final)
        return output_final

    except subprocess.CalledProcessError as e:
                       print("Error" + e.output)
                       pass

as you can see it is printing out the path to the file that i am returning -

/private/var/folders/lx/kvs2jbr52gj0ll9mcpm35j4c0000gn/T/gradio/30a2a6abd0a693be05828e4645c14d2839bbae2f/Australia and New Zealand Banking Group April Green Bean Packagingprompt_2.txt
Traceback (most recent call last):
  File "/Users/schhatbar/anaconda3/envs/unity/lib/python3.9/site-packages/gradio/queueing.py", line 527, in process_events
    response = await route_utils.call_process_api(
  File "/Users/schhatbar/anaconda3/envs/unity/lib/python3.9/site-packages/gradio/route_utils.py", line 270, in call_process_api
    output = await app.get_blocks().process_api(
  File "/Users/schhatbar/anaconda3/envs/unity/lib/python3.9/site-packages/gradio/blocks.py", line 1870, in process_api
    data = [
  File "/Users/schhatbar/anaconda3/envs/unity/lib/python3.9/site-packages/gradio/blocks.py", line 1871, in <listcomp>
    await self.postprocess_data(fn_index, list(o), state)
  File "/Users/schhatbar/anaconda3/envs/unity/lib/python3.9/site-packages/gradio/blocks.py", line 1725, in postprocess_data
    outputs_cached = await processing_utils.async_move_files_to_cache(
  File "/Users/schhatbar/anaconda3/envs/unity/lib/python3.9/site-packages/gradio/processing_utils.py", line 479, in async_move_files_to_cache
    return await client_utils.async_traverse(
  File "/Users/schhatbar/anaconda3/envs/unity/lib/python3.9/site-packages/gradio_client/utils.py", line 999, in async_traverse
    return await func(json_obj)
  File "/Users/schhatbar/anaconda3/envs/unity/lib/python3.9/site-packages/gradio/processing_utils.py", line 453, in _move_to_cache
    temp_file_path = await block.async_move_resource_to_block_cache(
  File "/Users/schhatbar/anaconda3/envs/unity/lib/python3.9/site-packages/gradio/blocks.py", line 286, in async_move_resource_to_block_cache
    temp_file_path = processing_utils.save_file_to_cache(
  File "/Users/schhatbar/anaconda3/envs/unity/lib/python3.9/site-packages/gradio/processing_utils.py", line 257, in save_file_to_cache
    temp_dir = hash_file(file_path)
  File "/Users/schhatbar/anaconda3/envs/unity/lib/python3.9/site-packages/gradio/processing_utils.py", line 189, in hash_file
    with open(file_path, "rb") as f:
IsADirectoryError: [Errno 21] Is a directory: '/'

This code was working fine before i updated gradio to the latest version.