Streamlit App works on localhost but does not on Cloud ASR and OCR are not working

this is my repository - GitHub - aditya230302/Lexi
main.py file is the one I am deploying.
The app works fine on local host but on Cloud its showing:

when using audio features:

OSError: 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.11/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 600, in _run_script
    exec(code, module.__dict__)File "/mount/src/lexi/Main.py", line 401, in <module>
    with sr.Microphone() as source:
         ^^^^^^^^^^^^^^^File "/home/adminuser/venv/lib/python3.11/site-packages/speech_recognition/__init__.py", line 99, in __init__
    self.audio = NoneFile "/home/adminuser/venv/lib/python3.11/site-packages/pyaudio/__init__.py", line 812, in get_default_input_device_info
    device_index = pa.get_default_input_device()
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

and when using OCR:

AttributeError: 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.11/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 600, in _run_script
    exec(code, module.__dict__)File "/mount/src/lexi/Main.py", line 517, in <module>
    ocr_result_image = perform_ocr_on_image(image_bytes, selected_ocr_language_image)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File "/mount/src/lexi/Main.py", line 273, in perform_ocr_on_image
    result = reader.readtext(img_np)
             ^^^^^^^^^^^^^^^^^^^^^^^File "/home/adminuser/venv/lib/python3.11/site-packages/easyocr/easyocr.py", line 464, in readtext
    bbox_min_size = bbox_min_size, max_candidates = max_candidatesFile "/home/adminuser/venv/lib/python3.11/site-packages/easyocr/easyocr.py", line 383, in recognize
    image_list, max_width = get_image_list(h_list, f_list, img_cv_grey, model_height = imgH)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File "/home/adminuser/venv/lib/python3.11/site-packages/easyocr/utils.py", line 613, in get_image_list
    crop_img,ratio = compute_ratio_and_resize(crop_img,width,height,model_height)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File "/home/adminuser/venv/lib/python3.11/site-packages/easyocr/utils.py", line 576, in compute_ratio_and_resize
    img = cv2.resize(img,(int(model_height*ratio),model_height),interpolation=Image.Resampling.LANCZOS)

can someone help me resolve this issue

This aproach will not work as soon as the application runs on any hosted environment, because there is neither a microphone nor a camera, at least these code lines below will not work, but there are probably more issues.

with sr.Microphone() as source:  # there is no microphone on the server
...
cap = cv2.VideoCapture(0)  # there is also no camera

This is a common misconception about how streamlit works. Everything has to go through the browser or browser APIs. You have to use streamlit components that can access audio/video devices.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.