PermissionError: [Errno 13] Permission denied /app of using llamaindex

Summary

Hello there!
I have deployed app of using llamaindex. The app worked on localhost but it don’t work on streamlit could.

Please tell me how to fix.
Thank you.

Steps to reproduce

Code snippet:

ImageReader = download_loader("ImageReader")

error message:

File "/home/adminuser/venv/lib/python3.11/site-packages/llama_index/readers/download.py", line 117, in download_loader

os.makedirs(dirpath)
File "<frozen os>", line 225, in makedirs
PermissionError: [Errno 13] Permission denied: '/home/adminuser/venv/lib/python3.11/site-packages/llama_index/readers/llamahub_modules'
1 Like

The file path you mentioned works in your local machine but that file dont exist in streamlit cloud
so you need to keep correct path

2 Likes

Thank you for your reply. Please tell me how to keep correct path.

1 Like

like create a folder in your project and place all files in this directory there
and change the path to this new path

or if its a library then access it as library instead of accessing it like file

Can you share a small, complete code snippet which reproduces this issue?

Thank you for your reply.

import streamlit as st
import os
import re
from PIL import Image
import shutil #フォルダを中身毎削除
from pathlib import Path
from llama_index import download_loader
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
import subprocess #コマンドを実行
from webdriver_manager.chrome import ChromeDriverManager 
st.markdown('### 配送関連情報取得app')

st.caption('llamaindex ocr')

os.environ['OPENAI_API_KEY'] = st.secrets['OPENAI_API_KEY']

temp_dir = Path("data")

temp_dir.mkdir(exist_ok=True)

uploaded_file = st.file_uploader("画像ファイルをアップロードしてください", type=["png", "jpeg"])

image_path = ''

if uploaded_file is not None:

image = Image.open(uploaded_file)

image_path = temp_dir / uploaded_file.name

image.save(image_path)

else:

st.warning("PNGファイルをアップロードしてください")

st.stop()

ImageReader = download_loader("ImageReader")

loader = ImageReader(text_type = "plain text")

documents = loader.load_data(file=image_path)

doc = documents[0]

doc_text = doc.text

pattern = r"\d+"

num = re.findall(pattern, doc_text) #リスト形式

num = num[0]

st.markdown('###### 濃飛運輸倉庫 問い合わせNo')

st.code(num)

App of getting text from image. I want to take number from text.
Thanks.

Thanks for sharing that! I think the problem is that, on Community Cloud, you are not able to create the directories needed in the default location. I would recommend trying something like this:

ImageReader = download_loader("ImageReader", custom_path="local_dir")

That should change the code to download the model to put it in local_dir/ rather than the default location. I don’t know for sure if that will work, but that is what I would try next.

1 Like

Cool app, by the way!

Thank you for your reply. I don’t know how to do like this.

For your advice my app worked! The app can get number from image.
I don’t know how to fix then I’m very happy!

But on next step of the app, another error occured.
it’s about selenium. I hope you look at it.

Thank you so much!

Hi, thanks so much for your reply on this issue! I’m actually running into the same problem and wanted to ask for your advice.

Here’s my current code snippet:

 ImageReader = download_loader("ImageReader", custom_path="/mount/src/llm-applications/local_dir")

And here is the error I’m running into when clicking on Manage App:

Traceback (most recent call last):
  File "/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 534, in _run_script
    exec(code, module.__dict__)
  File "/mount/src/llm-applications/pages/8_✨_Legal_Data_Chatbot_Scanned_Docs.py", line 275, in <module>
    main()
  File "/mount/src/llm-applications/pages/8_✨_Legal_Data_Chatbot_Scanned_Docs.py", line 227, in execute
    func(*args, **kwargs)
  File "/mount/src/llm-applications/pages/8_✨_Legal_Data_Chatbot_Scanned_Docs.py", line 263, in main
    qa_chain = setup_qa_chain(uploaded_files)
  File "/usr/local/lib/python3.9/contextlib.py", line 79, in inner
    return func(*args, **kwds)
  File "/mount/src/llm-applications/pages/8_✨_Legal_Data_Chatbot_Scanned_Docs.py", line 156, in setup_qa_chain
    ImageReader = download_loader("ImageReader")
  File "/home/adminuser/venv/lib/python3.9/site-packages/llama_index/readers/download.py", line 49, in download_loader
    reader_cls = download_llama_module(
  File "/home/adminuser/venv/lib/python3.9/site-packages/llama_index/download/module.py", line 214, in download_llama_module
    dirpath = initialize_directory(custom_path=custom_path, custom_dir=custom_dir)
  File "/home/adminuser/venv/lib/python3.9/site-packages/llama_index/download/utils.py", line 86, in initialize_directory
    os.makedirs(dirpath)
  File "/usr/local/lib/python3.9/os.py", line 225, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/home/adminuser/venv/lib/python3.9/site-packages/llama_index/download/llamahub_modules'

Also sharing the deployed app link: https://llm-applications.streamlit.app/Legal_Data_Chatbot_Scanned_Docs

I’d appreciate any advice on this, please!

Thank you :slight_smile:

1 Like

Same problem, same solution.

Hi! Thanks for your reply :slight_smile: I actually tried that solution above but got the same error, hence I wanted to ask for further clarification. Thank you!

1 Like

Here’s how I tried to implement the solution above:

ImageReader = download_loader("ImageReader", custom_path="local_dir")

And here’s the error that I’m getting on the Manage App tab:

Could you please let me know if there’s an issue in how I’m implementing the above solution? Or, if the error is something else, could you please direct me to the appropriate resources?

Thanks for your time! :slight_smile:

1 Like

The traceback shows that ImageReader = download_loader("ImageReader") is being executed, without custom_path. If that doesn’t match the code in github, then you may need to reboot or redeploy the application.