How tu run opencv-python in streamlit cloud?

I can’t run app with opencv-python or opencv-python-headless in streamlit cloud.

Even if I try to do something like this

import os
os.system(‘pip install opencv-python-headless’)

I got always this error:

ModuleNotFoundError: This app has encountered an error. The original error message is redacted to prevent data leaks. Full error details have been recorded in the logs (if you’re on Streamlit Cloud, click on ‘Manage app’ in the lower right of your app).

Traceback:

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/c_convert/c_convert.py", line 7, in <module>
    import cv2

Please help me

KR

Michał

Please share a link to your public github repo.

This one is private. Is this a problem - I’m asking because this is my first private app ? and I simply don’t know

I have this link https://github.com/Mike7205/c_convert/settings/keys

It is private, therefore no access…

No is private and error is still the same ModuleNotFoundError: This app has encountered an error. The original error message is redacted to prevent data leaks. Full error details have been recorded in the logs (if you’re on Streamlit Cloud, click on ‘Manage app’ in the lower right of your app).

Traceback:

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/c_convert/c_convert.py", line 7, in <module>
    import cv2

https://cconvert-kryxwnfalvamuqy36da8wv.streamlit.app/

Without seeing the actual code in the repo i cannot help. Most of the time this error is pretty trivial and you waste a lot of time guessing if you don’t see the code…

Yes please. It run’s locally.

import streamlit as st
import cv2
import numpy as np
import os

st.header(‘Konwerter niebieskich stron zeskanowanych w formie pliku jpg’)
up_file = st.file_uploader(“Wybierz plik jpg”)
if up_file is not None:
file_name = os.path.splitext(up_file.name)[0]
# Read the images
file_bytes = np.asarray(bytearray(up_file.read()), dtype=np.uint8)
img = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR)

# Resizing the image
image = cv2.resize(img, (1700, 2600))
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)

# Defining lower and upper bound HSV values
lower = np.array([0, 50, 50]) #[0, 50, 50]
upper = np.array([204, 255, 255]) #[204, 255, 255]

# Defining mask for detecting color
mask = cv2.inRange(hsv, lower, upper)

# Convert color on the image to black where we found blue
image[mask>0]=(192,192,192)  #(51,0,0) is black  (192,192,192) light grey

file_name_input = st.text_input('Tutaj możesz wprowadzić dowolną nazwę pliku po konwersji', file_name+'_B.jpg')
st.write('Nazwa pliku po konwersji to', file_name_input)
#cv2.imwrite(file_name_input,image)
#st.subheader('To jest wynik konwersji')
#st.image(file_name_input)
#st.download_button('Download gotowej wersji', file_name_input)

# Convert the processed image back to bytes
is_success, im_buf_arr = cv2.imencode(".jpg", image)
byte_im = im_buf_arr.tobytes()

# Display the processed image
st.subheader('To jest wynik konwersji')
st.image(byte_im, use_column_width=True)

# Provide a download button for the processed image
st.download_button('Download gotowej wersji', byte_im, file_name=file_name_input, mime='image/jpeg')

Therefore we need to see the whole repo, because you have to install the dependencies on streamlit cloud and usually there is the problem.

What you need just tell me ?

https://github.com/Mike7205/c_convert

You need this link ?

That link is not useful.

This is not my first app in streamlit cloud. The problem is, that I have to use another library: cv2 . And there is a problem with this library in streamlit cloud.

Well but it exsists:

And these are the requirements:

But we cannot see it, probably because you made it private.

Your dependency file is misspelled. It’s missing a u in requirements.txt.

And remove os from the file.

For now I’ve created new public repositoryand can’t run the app either:

New script, new git repository, new item in your streamlit.io and nothing works with or without os:

I am under the impression that you misspelled requirements.txt again.